Results 1 to 3 of 3

Thread: Can't save to text file with universal app

  1. #1
    Kenne76 is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2016
    Rep Power

    Can't save to text file with universal app

    I can't save any changes to the text file settings.txt , but reading the file works.
    The code is
    private async void LedShow_Loaded(object sender, RoutedEventArgs e)
    var path = @"settings.txt";
    var folder = Windows.ApplicationModel.Package.Current.Installed Location;
    var file = await folder.GetFileAsync(path);
    var lines = await Windows.Storage.FileIO.ReadLinesAsync(file);
    sliderDelay.Value = Convert.ToInt32(lines[0]);
    textBlockDelayValue.Text = lines[0] + " seconds";
    buttonSave.IsEnabled = false;
    and the error message is

    An exception of type 'System.UnauthorizedAccessException' occurred in System.Private.CoreLib.dll but was not handled in user code
    Access is denied. (Excep_FromHResult 0x80070005) occurred
    Can someone help me?

  2. #2
    NebraskaCoder is offline C# Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jul 2016
    Rep Power
    Sounds like your application doesn't have permission to write to the folder it is located. Try checking the permissions on the folder and settings.txt file (if it already exists) or try running the application as an administrator.

    Sent from my SM-G935P using Tapatalk

  3. #3
    JohnH's Avatar
    JohnH is offline C# Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Rep Power
    By default, the only locations that an app can access without user consent are its package folder (read -only) and its app data folders (read-write). The package folder is accessed by using Windows.ApplicationModel.Package.Current.Installed Location, ...
    More info here: Common questions and answers about files and app data, part 2: Files - Building Apps for Windows
    and here: Store and retrieve settings and other app data


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts