保存文本文件uwp的问题

时间:2016-12-07 18:21:44

标签: uwp raspberry-pi3 windows-iot-core-10

当我尝试使用带有Windows 10 IoT的raspberry pi 3保存到文本文件时,我遇到了这个visual c#uwp代码的问题。

var path = @"urls.txt";
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync(path);
var lines = await Windows.Storage.FileIO.ReadLinesAsync(file);
(lines[0]) = textBoxRadio.Text;
(lines[1]) = textBoxRadio2.Text;
await Windows.Storage.FileIO.WriteLinesAsync(file, lines);

出现以下错误消息

  

0x75DC0D6F处的未处理异常   blinky.exe中的(twinapi.appcore.dll):0xC000027B:An   发生了应用程序内部异常(参数:0x038CF1D0,   00000001)。发生了,应用程序停止了。

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

您不能将文件写入安装目录。您应该将文件保存到Local,Roaming或Temp文件夹。例如,Local用于将资产存储在本地特定于应用程序的文件夹中。有关更多信息,请参阅Jerry Nixon的博客文章:http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

var path = @"urls.txt";
var installationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await installationFolder.GetFileAsync(path);
var lines = await Windows.Storage.FileIO.ReadLinesAsync(file);
(lines[0]) = textBoxRadio.Text;
(lines[1]) = textBoxRadio2.Text;

var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var newFile = await localFolder.CreateFileAsync(path);
await Windows.Storage.FileIO.WriteLinesAsync(newFile, lines);