不允许在 IsolatedStorageFileStream: Visual Studio 2010 Express f

本文关键字:2010 Express Studio Visual IsolatedStorageFileStream 不允许 | 更新日期: 2023-09-27 18:35:56

我遇到此错误:"IsolatedStorageFileStream上不允许操作。我正在使用Visual Studio 2010 express的电话c#。

这是我的代码:

        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))
                {
                }
            }
        }
        }

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

不允许在 IsolatedStorageFileStream: Visual Studio 2010 Express f

如果要从Web读取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);

    }

如您所见,我们使用异步资源下载操作完成时发生的 DownloadStringCompleteHandler。

最后要解析XML,您可以使用XElement类在此处提供更多信息