Read text file in project folder in Windows Phone 8.1 Runtime

If you want to read a file from your project you can for example do it like this:

string fileContent;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///example.txt"));
using (StreamReader sRead = new StreamReader(await file.OpenStreamForReadAsync()))
fileContent = await sRead.ReadToEndAsync();

Also please ensure that you have set the Build Action of your file as Content (it should be as default).

More about URI schemes you will find here at MSDN.

Leave a Comment