保存到XML文档
我的尝试弄清楚如何创建一个 Windows Phone 7的应用程序,我想更新/保存具有以下功能的XML文件:
I am "trying" to figure out how to create a Windows Phone 7 application and I would like to update/save an xml file with the following function:
XDocument xmlDoc = XDocument.Load("myApp.xml");
xmlDoc.Element("ocd").Add(new XElement("vDetails", new XElement("itemName", this.tb_Name.Text),
new XElement("Date", System.DateTime.Now.ToString()), new XElement("itemValue", "")));
xmlDoc.Save("data.xml");
然而,xmlDoc.Save线给人一种错误:的System.Xml的最佳重载的方法匹配.Linq.XDocument.Save(System.Xml.XmlWriter)有一些无效的参数。
However the xmlDoc.Save line is giving an error: The best overloaded method match for "System.Xml.Linq.XDocument.Save(System.Xml.XmlWriter) has some invalid arguments.
什么我需要做的纠正呢?
What do I need to do to correct this?
您需要保存到独立存储(或者其他一些地方)获得独立存储您的应用程序,打开一个流文件,并保存到流:使用(VAR存储= IsolatedStorageFile.GetUserStoreForApplication())
{
使用
You need to save to isolated storage (or a few other places). Get the isolated storage for your application, open a stream to a file, and save to the stream:
using (var storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (Stream stream = storage.CreateFile("data.xml"))
{
doc.Save(stream);
}
}