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 9248779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:01:29+00:00 2026-06-18T10:01:29+00:00

In my app I convert a bitmap to a png and store it in

  • 0

In my app I convert a bitmap to a png and store it in a file inside a folder. When I attempt to open the file again to write the second time I get an UnauthorisedAccessException saying the "Access is denied".
When Save button is clicked, the following function is called.

private async void SaveClicked(object sender, RoutedEventArgs e)
        {
            WriteableBitmap wb = new WriteableBitmap(InkCanvas2, null);
            Image image = new Image();
            image.Height = 150;
            image.Width = 450;
            image.Source = wb;
            await SaveToStorage(wb, image);
            TransparentLayer.Visibility = System.Windows.Visibility.Collapsed;   

        }

The SaveToStorage has the following code

private async Task SaveToStorage(WriteableBitmap i, Image im)
        {
            try
            {    
                  var dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);                    
                  using (var testpng = await dataFolder.OpenStreamForWriteAsync("testpng.png", CreationCollisionOption.ReplaceExisting)) 
// HITS EXCEPTION AND GOES TO CATCH BLOCK
                     {    
                       i.WritePNG(testpng);    
                       testpng.Flush();
                       testpng.Close();
                     }                    
            }  
            catch(Exception e)
            {
            string txt = e.Message;
            }
        }

It saves the first time with no error, the second time, throws exception. Any idea why this happens?

  • 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-18T10:01:31+00:00Added an answer on June 18, 2026 at 10:01 am

    I figured out! It is apparently because I did not include a fileexist check before trying to open it.

    I have re written the code like this

           IStorageFolder dataFolder = await local.CreateFolderAsync("Page", CreationCollisionOption.OpenIfExists);
                StorageFile Ink_File = null;
                //Using try catch to check if a file exists or not as there is no inbuilt function yet
                try
                {
                    Ink_File = await dataFolder.GetFileAsync("testpng.png");
                }
                catch (FileNotFoundException)
                {
                    return false;
                }
    
                try
                {
                    if (Ink_File != null)
                    {
    
                        using (var testpng = await Ink_File.OpenStreamForWriteAsync())
                        {
    
                            i.WritePNG(testpng);
    
                            testpng.Flush();
                            testpng.Close();
                            return true;
                        }
                    }
    
                }
                catch(Exception e)
                {
                    string txt = e.Message;
                    return false;
                }
                return false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that captures image from webcam,I convert it to bitmap, now
I'm trying to convert my app to ARC and the converter is throwing up
I have an app set up where I convert an NSString into an array
Is it posible to convert an ASP app to ASP.NET? I prefer to work
I'm using an app called Quarkee to convert a logo from SVG to Quartz
I need to convert a web app into ipad app. Stressing on style and
I am trying to convert some pages from my app to use cfc's, and
I am trying to convert the popular asp.net MVC 2.0 solr.net sample app code
I am trying to convert string to class name. My code is: app.actNum =
i'm just started dev-ing app for wp7 and I'm trying to convert a string

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.