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");
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?
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With