Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saving to xml document

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?

like image 820
webdad3 Avatar asked Jan 22 '23 01:01

webdad3


1 Answers

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);
    }
}
like image 63
Jon Skeet Avatar answered Feb 01 '23 00:02

Jon Skeet