[UWP] [C#]无法使用visual c#universal app保存到文本文件 [英] [UWP][C#]Can't save to text file with visual c# universal app
问题描述
我无法保存对文本文件settings.txt的任何更改,但读取文件有效。
I can't save any changes to the text file settings.txt , but reading the file works.
代码
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] +"秒数;;
buttonSave.IsEnabled = false;
}
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;
}
并且错误消息是
发生了'System.UnauthorizedAccessException'类型的异常在System.Private.CoreLib.dll中但未在用户代码中处理
访问被拒绝。 (Excep_FromHResult 0x80070005)发生了
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
有人可以帮助我吗?
推荐答案
嗨!
该应用程序的安装目录是一个只读位置。
这是Msdn的链接: https://msdn.microsoft.com/en-us/windows/uwp/files/file-access-permissions
希望它有用:)
这篇关于[UWP] [C#]无法使用visual c#universal app保存到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!