The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
Right Access Issues When Using Windows.ApplicationModel.Package.Current.InstalledLocation.CreateFolderAsync RRS feed

  • Question

  • Let me start off by saying I'm Universal Windows naïve to the highest degree. I understand and have used C# primarily for web apps so be gentle. So, I'm trying out this tutorial while learning universal apps: http://www.c-sharpcorner.com/UploadFile/99bb20/metro-style-app/

    and I can get it all working fine, but when it trys to create the local EMP folder it fails to -

    An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll but was not handled in user code

    Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    So, thinking this is a simple as hades question, but I'll be darned if I can't find that many references for how to fix it.

    I'm really enjoying learning Windows Universal App development. Making the move from c# code behind web apps using .net has been relatively easy considering the similar code behind modeling.

    My Visual Studio 2015 Info:

    Microsoft Visual Studio Community 2015
    Version 14.0.24720.00 Update 1
    Microsoft .NET Framework
    Version 4.6.01038

    Any help you can provide on what I have to imagine is a simple question above is appreciated.

    Saturday, February 13, 2016 1:37 PM

Answers

  • Of course, within minutes of writing the above I find the answer in the comments to the original tutorial! DOH!

    but if it helps anyone. this set of lines work as a replacement.

    Windows.Storage.StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("EMP", CreationCollisionOption.OpenIfExists);

    StorageFile st = await sf.CreateFileAsync("Employee.xml", CreationCollisionOption.OpenIfExists);

    await dom.SaveToFileAsync(st);

    • Marked as answer by Murdock_SE Saturday, February 13, 2016 1:46 PM
    Saturday, February 13, 2016 1:44 PM

All replies

  • Of course, within minutes of writing the above I find the answer in the comments to the original tutorial! DOH!

    but if it helps anyone. this set of lines work as a replacement.

    Windows.Storage.StorageFolder sf = await ApplicationData.Current.LocalFolder.CreateFolderAsync("EMP", CreationCollisionOption.OpenIfExists);

    StorageFile st = await sf.CreateFileAsync("Employee.xml", CreationCollisionOption.OpenIfExists);

    await dom.SaveToFileAsync(st);

    • Marked as answer by Murdock_SE Saturday, February 13, 2016 1:46 PM
    Saturday, February 13, 2016 1:44 PM
  • this document is also helpful: https://msdn.microsoft.com/en-us/library/windows/apps/hh465199

    Best Regards,
    Please remember to mark the replies as answers if they help

    Wednesday, March 9, 2016 2:35 AM