问题
I am having this error: "Operation not permitted on IsolatedStorageFileStream." I am using visual studio 2010 express for phone c#.
Here is my code:
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))
{
}
}
}
}
Thank you for your help! It's much appreciated.
回答1:
if you want to read a xml from the web you should use the WebClient class. WebClient provides common methods for sending data to and receiving data from a resource identified by a URI.
Here's a little example
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);
}
as you can see we use DownloadStringCompletedHandler that occurs when an asynchronous resource-download operation completes.
Finally to parse the XML you can use XElement class more informartion here
来源:https://stackoverflow.com/questions/19458514/operation-not-permitted-on-isolatedstoragefilestream-visual-studio-2010-express