Thanks to the below link, I've found out how to load a TXT file into my Windows Phone 8.1 app. My question is specifically tied to WHY my code doesn't work. (My code begins after link to the other StackOverflow question).
This is the same question, with a working answer. Read text file in project folder in Windows Phone 8.1 Runtime
I set the StorageFile as the relative location of the file on the phone. I then try and use that location to open a StreamReader. This small snippet compiles fine, however on execution, encounters a runtime error, and "firstFile" is empty/null.
const string filename = "FileToRead.txt";
StorageFile firstFile = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
using (StreamReader streamFirstFile = new StreamReader(await firstFile.OpenStreamForReadAsync()))
{
loadText_Button.Text = await streamFirstFile.ReadToEndAsync();
}
To hopefully further clarify this specific question, are the following two lines of code the same, and if not, how am I using it wrong?
ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Assets/FileToRead.txt"))
I even tried to set it as follows:
ApplicationData.Current.LocalFolder.GetFileAsync(String.Format("{0}{1}", "Assets/", fileName);
Thank you all in advance.