开发者

How do I embed and read a text file ina WP7 app?

开发者 https://www.devze.com 2023-01-20 05:18 出处:网络
I\'m trying to include a text file that contains some static data that I need to read in when the app starts up. I\'ve added the file and marked the Build Actio开发者_JS百科n to \"Resource\" but I\'m

I'm trying to include a text file that contains some static data that I need to read in when the app starts up. I've added the file and marked the Build Actio开发者_JS百科n to "Resource" but I'm unsure of how to actually read it in as a stream. Anyone know how to do this?


try this:

var resource = Application.GetResourceStream(
                               new Uri(@"/YOURASSEMBLYNAME;component/Stations.txt", 
                               UriKind.Relative));

StreamReader streamReader = new StreamReader(resource.Stream);

string x = streamReader.ReadToEnd();

That should work for you.


You can use the System.Windows.Application.GetResourceStream method:

var resource = System.Windows.Application.GetResourceStream(
                   new Uri("textfile.txt",UriKind.Relative));

should do the trick

0

精彩评论

暂无评论...
验证码 换一张
取 消