问题描述
这是一个从MSDN Forum Xml和.NET Framework移出的线程.
This is a thread that moved from MSDN Forum Xml and .NET Framework at.
症状是当用户对XML文件进行修改并将其保存回该文件时导致损坏.在台式机操作系统上不会出现相同的问题.在Win7手机上,当保存到新文件或删除文件时,首先可以防止损坏.所以 使我相信这是Win7 Phone平台问题,而不是Xml问题.请提供协助.谢谢
艾伦(MSFT)
原始问题如下:
The symptom was when user making modification on a XML file and saving it back to the file causing corruption. Same issue does NOT repro on a desktop OS. And on Win7 phone, When saving to a new file or delete the file first prevented the corruption. So it leads me to believe this is Win7 Phone platform issue rather than Xml issue. Please provide assistance. Thanks
Allen (MSFT)
The original question as follows:
我有两个更新XML的功能
I have two functions to update an XML
======
删除
======
//Deleting a specific station
private void RemoveStation(string idA)
{
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
try
{
using (storage)
{
if (storage.FileExists("fave.xml"))
{
//Reading and deleting the station
IsolatedStorageFileStream fileStream = storage.OpenFile("fave.xml", FileMode.Open, FileAccess.ReadWrite);
XDocument _doc = XDocument.Load(fileStream);
var item = from c in _doc.Element("stations").Elements("station")
where c.Attribute("id").Value == idA
select c;
item.Remove();
fileStream.Dispose();
//Updating the file
IsolatedStorageFileStream location = new IsolatedStorageFileStream("fave.xml", FileMode.Open, FileAccess.ReadWrite, storage);
System.IO.StreamWriter file = new System.IO.StreamWriter(location);
_doc.Save(file);
file.Dispose();
location.Dispose();
}
else
{
Console.WriteLine("fave.xml not found");
}
}
} catch (Exception e)
{
Console.WriteLine("Error P-RS: Error opening storage");
Console.WriteLine(e.StackTrace);
} finally
{
storage.Dispose();
}
}
推荐答案
这篇关于Windows Phone 7 XML隔离存储文件的损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!