Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8883601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:51:12+00:00 2026-06-14T20:51:12+00:00

This is my first silverlight application and I need to save a file in

  • 0

This is my first silverlight application and I need to save a file in my C: directory. My Silverlight app will make a connection with my webcam and then I will take an snapshot and then save it in my C: directory.

Look what I made

protected void photoButton_Click(object sender, RoutedEventArgs e)
        {
            this.src.CaptureImageCompleted += (s, a) =>
            {
                this.lastSnapshot = a.Result;
                this.snapshot.Visibility = Visibility.Visible;
                this.snapshot.Source = this.lastSnapshot;
                this.src.Stop();

                if (this.lastSnapshot != null)
                {
                    var pngStream = this.GetPngStream(lastSnapshot);
                    byte[] binaryData = new Byte[pngStream.Length];
                    long bytesRead = pngStream.Read(binaryData, 0, (int)pngStream.Length);

                    WriteBytesToFile("imagem.png", binaryData);
                }
            };

            src.CaptureImageAsync();
        }

        static public void WriteBytesToFile(string fileName, byte[] content)
        {            
            FileStream fs = new FileStream(fileName, FileMode.Create);
            BinaryWriter w = new BinaryWriter(fs);
            try
            {
                w.Write(content);
            }
            finally
            {
                fs.Close();
                w.Close();
            }
        } 

   protected Stream GetPngStream(WriteableBitmap bmp)
    {
        // Use Joe Stegman's PNG Encoder
        // http://bit.ly/77mDsv
        EditableImage imageData = new EditableImage(bmp.PixelWidth, bmp.PixelHeight);

        for (int y = 0; y < bmp.PixelHeight; ++y)
        {
            for (int x = 0; x < bmp.PixelWidth; ++x)
            {

                int pixel = bmp.Pixels[bmp.PixelWidth * y + x];

                imageData.SetPixel(x, y,
                            (byte)((pixel >> 16) & 0xFF),
                            (byte)((pixel >> 8) & 0xFF),
                            (byte)(pixel & 0xFF),
                            (byte)((pixel >> 24) & 0xFF)
                            );

            }
        }

        return imageData.GetStream();
    }

In my WriteBytesToFile I got the error File operation not permitted. Access to path is denied.. How can I save the snapshot in my C: directory with the name imagem.png ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:51:13+00:00Added an answer on June 14, 2026 at 8:51 pm

    Silverlight applications run in a sandbox by default and do not have any direct access to the file system. For a Silverlight application to have access to the local file system it must be installed as a trusted applicaiton. A trusted Silverlight 5 application will have access to the entire hard drive, but a Silverlight 4 application will only have access to the MyDocuments, MyMusic, MyPictures, and MyVideos folders.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team (3 developers) will be building a Silverlight LOB application. This is the
I'm trying to develop my first Silverlight navigation application. This application has 2 main
I am building my first Silverlight 3 + RI Services application and need some
How to create in-app step by step instructions? Like this ( first boot android
I have this issue: first, I execute a SQL query using Java and then
We're building a Silverlight application which will be offered as SaaS. The end product
I need to open window pop-up from Silverlight Out-of-Browser application. I've added parameter <param
I read this post, which explains how to play MIDI. I need to make
I have a Silverlight-Application which is hosted in a ASP.NET-Site. Now, I need to
For a project we need to add attachments to workitems through a Silverlight application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.