2016-12-07 22 views
0

當我嘗試保存到帶有Windows 10 IoT的樹莓派3的文本文件時,我遇到了此Visual c#uwp代碼的問題。保存與文本文件的問題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 (twinapi.appcore.dll)在blinky.exe未處理異常:0xC000027B:發生 應用程序內部異常(參數:0x038CF1D0, 00000001)。發生並且應用程序停止。

有人能幫助我嗎?

+0

什麼是您的調試器類型?是「**僅限本地**」嗎? –

回答

1

您不允許將文件寫入安裝目錄。您應該將文件保存到本地,漫遊或臨時文件夾。本地是爲了將資產存儲在本地的,特定於應用程序的文件夾中。請參閱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);