简体   繁体   中英

Use local file with StringReader

I'm developing an app for WP.

I'm using a XML file online, it's working fine but when I want to use the same XML file in local storing, this doesn't work...

I added it at my project.

To use it online, I'm using that :

client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://exemple.com/news.xml"), "News");

And in my function client_DownloadStringCompleted, I read like that:

StringReader stringReader = new StringReader(e.Result);

So this it's working but with my local file I'm doing like that directly and it's not working :

StringReader stringReader = new StringReader("news.xml");

Do you know how I can fix that ?

Thank you for your help.

EDIT : It's ok, thanks for your help !

I wrote that :

var resource = Application.GetResourceStream(new Uri(@"/YOURASSEMBLYNAME;component/news.xml", UriKind.Relative));
StreamReader streamReader = new StreamReader(resource.Stream);
StringReader stringReader = new StringReader(streamReader.ReadToEnd());

And I used the file like a resource.

The parameter of the StringReader constructor is the string that you want to read.

In the code that you have that does not work, you are reading the name of the file not the contents of the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM