0

I have a folder with text files needed to launch the uwp desktop application I'm working on. I include this folder in the project. The question is how to read the existing text files in the folder? I tried the code below, but it didn't work. Throws a bad path exception.

string strPath = "ms-appx:///MyData/structure.txt";
string strStructure = File.ReadAllText(strPath);
Jose Afonso
  • 117
  • 8

1 Answers1

0

I found a solution to the problem. I placed the file in the root folder of the project and used the following code.

StorageFolder installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile file = await installedLocation.GetFileAsync("structure.lst");
IList<string> data = await FileIO.ReadLinesAsync(file);
Jose Afonso
  • 117
  • 8