我正在从 Internet 读取 XML 文件。我正在将它写入隔离存储,然后我喜欢阅读它。这是代码
IsolatedStorageFile isf=IsolatedStorageFile.GetUserStoreForApplication();
private void findNearestButton_Click(object sender, RoutedEventArgs e)
{
findCity(isf);
}
private void findCity(IsolatedStorageFile isf)
{
filePath = AppResource.exchangeOfficesFile;
if (!isf.FileExists(filePath.ToString()))
{
takeXMLOnLine(isf,filePath);
}
parseXMLfile(isf,filePath);
}
private void takeXMLOnLine(IsolatedStorageFile isf, string filePath)
{
System.Uri targetUri = new System.Uri(AppResource.exchangeOfficesURI);
WebClient client = new WebClient();
client.DownloadStringAsync(targetUri);
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
using (IsolatedStorageFileStream rawStream = isf.OpenFile(filePath, FileMode.Create))
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.ConformanceLevel = ConformanceLevel.Auto;
using (XmlWriter writer = XmlWriter.Create(rawStream, settings))
{
string xmlResponse = e.Result.ToString();
xmlResponse = xmlResponse.Replace("<", "<");
xmlResponse = xmlResponse.Replace(">", ">");
writer.WriteString(xmlResponse);
// Write the XML to the file.
writer.Flush();
}
}
}
private void parseXMLfile(IsolatedStorageFile isf, string filePath)
{
using (IsolatedStorageFileStream str = isf.OpenFile(filePath, FileMode.Open, FileAccess.Read))
{
StreamReader reader = new StreamReader(str);
string line;
while ((line = reader.ReadLine()) != null)
{
MessageBox.Show(line);
}
reader.Close();
}
}
当我运行代码时,在此行出现 Operation not allow on IsolatedStoreageFileStream 错误
using (IsolatedStorageFileStream str = isf.OpenFile(filePath, FileMode.Open, FileAccess.Read))
有人可以帮我吗?