Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将本地文件与StringReader一起使用_C#_Xml_Windows Phone 7_Stringreader - Fatal编程技术网

C# 将本地文件与StringReader一起使用

C# 将本地文件与StringReader一起使用,c#,xml,windows-phone-7,stringreader,C#,Xml,Windows Phone 7,Stringreader,我正在为WP开发一个应用程序 我在网上使用一个XML文件,它工作得很好,但是当我想在本地存储中使用同一个XML文件时,它不起作用 我在我的项目中添加了它 要在线使用它,我使用的是: client.DownloadStringCompleted += client_DownloadStringCompleted; client.DownloadStringAsync(new Uri("http://exemple.com/news.xml"), "News"); 在我的函数client_Down

我正在为WP开发一个应用程序

我在网上使用一个XML文件,它工作得很好,但是当我想在本地存储中使用同一个XML文件时,它不起作用

我在我的项目中添加了它

要在线使用它,我使用的是:

client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://exemple.com/news.xml"), "News");
在我的函数client_DownloadStringCompleted中,我读到如下内容:

StringReader stringReader = new StringReader(e.Result);
所以这是可行的,但对于我的本地文件,我直接这样做,但它不起作用:

StringReader stringReader = new StringReader("news.xml");
你知道我怎样才能解决这个问题吗

谢谢你的帮助

编辑: 没关系,谢谢你的帮助

我写道:

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

我像使用资源一样使用该文件。

StringReader构造函数的参数是您要读取的字符串


在不起作用的代码中,您读取的是文件名而不是文件内容。

文件首先是如何进入本地存储的?当然,除非你让用户下载。默认情况下,该文件是本地文件。我想将StringReader用于此本地文件。请参阅此问题的答案--您需要将该文件作为资源嵌入。谢谢ChrisF,我在您的帮助下解决了此问题!