CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2015
    Posts
    7

    Can't save to text file with visual c# 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.InstalledLocation;
    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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Can't save to text file with visual c# universal app.

    I can't save any changes to the text file settings.txt
    ...
    Access is denied
    What are the permissions of the file? Have you got write access?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured