How do I read an embedded text file on Windows Phone 8.1?

不问归期 提交于 2019-12-23 04:04:21

问题


(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?


回答1:


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);


来源:https://stackoverflow.com/questions/24081817/how-do-i-read-an-embedded-text-file-on-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!