Saving issue with text file uwp

0

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?

uwp
raspberry-pi3
windows-iot-core-10
asked on Stack Overflow Dec 7, 2016 by Ken • edited Dec 8, 2016 by Alexander Ciesielski

1 Answer

1

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);
answered on Stack Overflow Dec 7, 2016 by mm8

User contributions licensed under CC BY-SA 3.0