Ken
Ken

Reputation: 43

Saving issue with text file uwp

I have problem with this visual c# uwp code when I am trying to save to text file with raspberry pi 3 with Windows 10 IoT.

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);

Following error message appears

Unhandled exception at 0x75DC0D6F (twinapi.appcore.dll) in blinky.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x038CF1D0, 0x00000001). occurred and the application halted.

Can someone help me?

Upvotes: 0

Views: 169

Answers (1)

mm8
mm8

Reputation: 169360

You are not allowed to write a file to the installation directory. You should save the file to the Local, Roaming or Temp folder. Local is for example meant to store assets in a local, application-specific folder. Please refer to Jerry Nixon's blog post for more information: 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);

Upvotes: 1

Related Questions