2013-10-18 70 views
0

我遇到此错误:“在IsolatedStorageFileStream上不允许操作。”我正在使用visual studio 2010 express for phone c#。IsolatedStorageFileStream不允许操作:Visual Studio 2010 Express for Phone

这里是我的代码:

 public void LoadData() 
     { 
      string xmlUrl = "http://datastore.unm.edu/events/events.xml"; 

     using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) 
     { 

      using (var isoFileStream = new IsolatedStorageFileStream(xmlUrl, FileMode.Open, FileAccess.ReadWrite, FileShare.Read, storage)) 
      { 
       using (XmlReader xreader = XmlReader.Create(isoFileStream)) 
       { 

       } 

      } 

     } 
     } 

谢谢您的帮助!非常感谢。

+0

IsolatedStorage是本地文件,而不是远程(基于网络的)文件。你想从网上读取XML吗? –

+0

谢谢你的回应,是的,我试图从网上读取文件。 – visualbasicNoob9000

回答

0

如果你想从网上读取一个XML,你应该使用WebClient类。 WebClient提供了通过URI标识的资源发送数据和接收数据的常用方法。

这里有一个小例子

private WebClient webClient; 

    public Example() 
    { 
     webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted); 
     webClient.DownloadStringAsync(new Uri("http://datastore.unm.edu/events/events.xml", UriKind.Absolute)); 
    } 

    private void DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 
    { 

     XElement Xmlparse = XElement.Parse(e.Result); 


    } 

,你可以看到我们使用异步资源下载操作完成时发生DownloadStringCompletedHandler。

最后解析XML,你可以使用的XElement类more informartion here

相关问题