我喜欢从 Internet 下载 XML 文件并将其写入到 IsolatedStorage 文件中。这是我正在使用的代码
public StreamReader readerForXml;
private void find()
{
string filePath = "myFile.xml";
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("People2.xml", FileMode.Create, myIsolatedStorage))
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(rawStream, settings))
{
System.Uri targetUri = new System.Uri("http://dl.dropbox.com/u/29465448/ExchangeOffices.xml");
WebClient client = new WebClient();
try
{
client.DownloadStringAsync(targetUri);
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
writer.WriteString(sReader.ToString());
writer.Flush();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
} }
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
sReader = new StreamReader(e.Result.ToString());
}
我得到 StreamReader sReader 的 NullReferenceException,有人有同样的问题吗?谢谢