locked
Unable to write to Installation Folder - Access Denied RRS feed

  • Question

  • For some reason this has stopped working (I now get Access Denied).

    Windows.Storage.StorageFile file =
    await InstallationFolder.CreateFileAsync(@"outputX.txt", Windows.Storage.CreationCollisionOption.ReplaceExisting);


    If I look at the folder in Explorer it seems as though it's set to read-only. Even if I unset this when I run the app (i.e. Build then Deploy) it still fails with the same result. I'm not sure if I should be using this folder or not. Is VS2013 recreating this folder when you Build/Deploy and then setting to read-only?

    If anyone can point me in the right direction I'd be very grateful.

    Thank you in anticipation.

    Friday, December 20, 2013 7:49 PM

Answers

  • This is correct behavior: installed apps live in Program Files and do not have write access to their install directory.

    Instead they should use their app data directories. See Accessing app data with the Windows Runtime

    --Rob

    • Marked as answer by Anne Jing Wednesday, January 1, 2014 5:24 AM
    Friday, December 20, 2013 7:54 PM
    Moderator
  • Or is it just a matter of copying the file from the Installation folder to the App Data folder on first use of the app?

    You got it! You need to copy the database to the app data folder before you can write to it.

    --Rob

    • Marked as answer by Ted Weston Saturday, January 4, 2014 4:43 PM
    Saturday, January 4, 2014 3:49 PM
    Moderator

All replies

  • This is correct behavior: installed apps live in Program Files and do not have write access to their install directory.

    Instead they should use their app data directories. See Accessing app data with the Windows Runtime

    --Rob

    • Marked as answer by Anne Jing Wednesday, January 1, 2014 5:24 AM
    Friday, December 20, 2013 7:54 PM
    Moderator
  • Thank you for your prompt reply, Rob. I know understand more about the Installation folder, but I wonder if you can help me further?

    My project involves access to a data file (txt) which needs to be deployed when the app is installed but can then be updated by the user. This file is in the Assets folder of the project and it seems as though this is placed in the Installation Folder, when deployed. How do I get this file to be deployed in the App Data folder so I can allow updates? Or is it just a matter of copying the file from the Installation folder to the App Data folder on first use of the app?

    Thanks for your help.

    Saturday, January 4, 2014 3:41 PM
  • Or is it just a matter of copying the file from the Installation folder to the App Data folder on first use of the app?

    You got it! You need to copy the database to the app data folder before you can write to it.

    --Rob

    • Marked as answer by Ted Weston Saturday, January 4, 2014 4:43 PM
    Saturday, January 4, 2014 3:49 PM
    Moderator
  • Thank you again, Rob. Happy New Year.
    Saturday, January 4, 2014 4:42 PM