Reputation: 16960
(I can find many answers for Windows Phone 7 which probably work Windows Phone 8/8.1 Silverlight, but not for Windows Phone [Store] 8.1)
While testing my application, I want to use a dummy server response. Since it's a large amount of data that includes quotation marks, I don't want to use a constant string and have to escape everything.
How can I read a text file that's included with my Windows Phone 8.1 application?
Upvotes: 1
Views: 4175
Reputation: 16960
For this example, I have a file called sample-response.txt
and its 'Build Action' properties is set to 'Content'.
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("sample-response.txt");
var contents = await Windows.Storage.FileIO.ReadTextAsync(file);
and if you want to double-check that it's been read ok
Debug.WriteLine(contents);
Upvotes: 1