我正在尝试从xml文件Wp8中删除一个节点
您好,我正在尝试使用ISO存储从xml文件中删除一个元素,节点被删除,但xml变形 代码是:我正在尝试从xml文件Wp8中删除一个节点,xml,windows-phone-8,Xml,Windows Phone 8,您好,我正在尝试使用ISO存储从xml文件中删除一个元素,节点被删除,但xml变形 代码是: public void deleteFromXML(string appName) { using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication()) { using (var stream = isoStorage.OpenFile("ISOconfig
public void deleteFromXML(string appName)
{
using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var stream = isoStorage.OpenFile("ISOconfig.xml", FileMode.Open, FileAccess.ReadWrite))
{
XDocument xml = XDocument.Load(stream);
xml.Descendants("ContainerApp")
.Where(x => x.Element("AppName").Value.Equals(appName))
.Remove();
// stream.Position = 0;
// xml.Save(stream);
stream.Close();
// Save To ISOconfig.xml File oeration not permited on IsolatedStorageFileStream
using (IsolatedStorageFileStream newStream = new IsolatedStorageFileStream("ISOconfig.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None, isoStorage))
{
xml.Save(newStream);
}
}
}
}
所做的更改是在linq查询关闭流并将其保存为: stream.Close(); //保存到ISOconfig.xml文件 使用(IsolatedStorageFileStream newStream=新的IsolatedStorageFileStream(“ISOconfig.xml”,FileMode.Create,isoStorage)) { Save(newStream);
}如果您需要添加上下文/代码,请编辑您的问题,不要将其作为答案发布。