Reputation:
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.
Upvotes: 2
Views: 4842
Reputation: 65431
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.
Upvotes: 3