Saving in an XML document

I am " trying " to figure out how to create a Windows Phone 7 application , and I would like to update / save the 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 gives an error: the best overloaded method match for "System.Xml.Linq.XDocument.Save (System.Xml.XmlWriter) has several invalid arguments.

What do I need to do to fix this?

+4
source share
2 answers

You need to save to isolated storage (or several other places). Get isolated storage for your application, open the stream in a file and save it in the stream:

 using (var storage = IsolatedStorageFile.GetUserStoreForApplication()) { using (Stream stream = storage.CreateFile("data.xml")) { doc.Save(stream); } } 
+8
source

The Windows Phone Developer Blog does most of the work with the application execution model.

I think it’s important to distinguish between β€œclosing” the application and the application that is being monitored.

Closing the application is just the result of a user clicking the hardware Back button enough time to move back through the pages of your application, past the first page of applications.

A deactivated application occurs when a different application takes control of the foreground - for example, an incoming phone call, startup, or user by pressing the Windows Button. In both cases, the application will be disconnected (not closed). Before we go into the intricacies of a deactivated event, we can make sure that we all understand that when you deactivate your application ends (at the end). It is so simple; your code does not work background, so your application terminates. However, unlike a closed application, a deactivated application gets buried. Do not confuse, the process of gravestone applications is still ending. But unlike a closed application in which the WP system runs, it deletes any traces of the application when the application is deactivated, the WP operating system stores a record (tombstone) of the state of the application. Basically, the WP operating system stores the tombstone application, which becomes part of the back-stack application for phones, which is a magazine that allows the use of the hardware back button to improve navigation functions.

Application Execution Model

As for testing, the idea could be to reorganize the code and add a log for various points of the event, such as closure or burial, etc.

+1
source

All Articles