locked
windows 8 store app- authorize exception

    Question

  • Hellow

    i am tring to write simple json file localy

    in my windows 8 store app

    but i get an exception : UnauthorizedAccessException

    this is the code:

     internal async static void Save(List<RecipeDataGroup> list)
            {
               
                string json = JsonConvert.SerializeObject(list);
              
                 var _file = await Package.Current.InstalledLocation.CreateFileAsync("Data\\Recipes2.txt");
    
                await Windows.Storage.FileIO.WriteTextAsync(_file ,json );
                
              
    
            }
    How to solve it ?

    m.sh

    Tuesday, February 17, 2015 3:26 PM

Answers

  • You posted to the wpf forum.

    .

    I think I know what the problem is though.

    You're limited to where you can write.

    The simplest option is to use LocalFolder

    Like:

    StorageFolder folder =
        Windows.Storage.ApplicationData.Current.LocalFolder;
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758325.aspx

    .

    Please post any further windows store app questions to one of the forums for that:

    https://social.msdn.microsoft.com/Forums/windowsapps/en-us/home?category=windowsapps


    Hope that helps.
    Recent Technet articles: Property List Editing ;   Dynamic XAML

    • Marked as answer by M.Shim Wednesday, February 18, 2015 11:56 PM
    Tuesday, February 17, 2015 3:33 PM
  • You cannot create a file in the installation folder of the app because it is a read-only location as documented here:  https://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx

    You could try to create the file in the local folder:

     var _file = await ApplicationData.Current.LocalFolder.CreateFileAsync("Recipes2.txt");
     await Windows.Storage.FileIO.WriteTextAsync(_file ,json );

    But please ask any questions related to Windows Store Apps here: https://social.msdn.microsoft.com/Forums/windowsapps/en-us/home?category=windowsapps


    Please remember to mark helpful posts as answer to close your threads.

    Tuesday, February 17, 2015 3:34 PM
  • Or you could use local folder.

    Oh wait.

    I already suggested that.


    Hope that helps.
    Recent Technet articles: Property List Editing ;   Dynamic XAML

    • Marked as answer by M.Shim Wednesday, February 18, 2015 11:56 PM
    Tuesday, February 17, 2015 7:50 PM

All replies

  • You posted to the wpf forum.

    .

    I think I know what the problem is though.

    You're limited to where you can write.

    The simplest option is to use LocalFolder

    Like:

    StorageFolder folder =
        Windows.Storage.ApplicationData.Current.LocalFolder;
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh758325.aspx

    .

    Please post any further windows store app questions to one of the forums for that:

    https://social.msdn.microsoft.com/Forums/windowsapps/en-us/home?category=windowsapps


    Hope that helps.
    Recent Technet articles: Property List Editing ;   Dynamic XAML

    • Marked as answer by M.Shim Wednesday, February 18, 2015 11:56 PM
    Tuesday, February 17, 2015 3:33 PM
  • You cannot create a file in the installation folder of the app because it is a read-only location as documented here:  https://msdn.microsoft.com/en-us/library/windows/apps/hh967755.aspx

    You could try to create the file in the local folder:

     var _file = await ApplicationData.Current.LocalFolder.CreateFileAsync("Recipes2.txt");
     await Windows.Storage.FileIO.WriteTextAsync(_file ,json );

    But please ask any questions related to Windows Store Apps here: https://social.msdn.microsoft.com/Forums/windowsapps/en-us/home?category=windowsapps


    Please remember to mark helpful posts as answer to close your threads.

    Tuesday, February 17, 2015 3:34 PM
  • Or you could use local folder.

    Oh wait.

    I already suggested that.


    Hope that helps.
    Recent Technet articles: Property List Editing ;   Dynamic XAML

    • Marked as answer by M.Shim Wednesday, February 18, 2015 11:56 PM
    Tuesday, February 17, 2015 7:50 PM
  • Thanks you all, it work.

    but i got for any build- new directory...

    how can i use the file in development time ?


    m.sh

    Wednesday, February 18, 2015 11:59 PM