インターネットから 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))
誰か助けてくれませんか?