How to save XML file before update?
- by Robert Iagar
Right so I have a simple app that consists of a calendar a Set Event button and list box that populates using a DataTemplate in WPF. When I build the app the Events.xml file is like this:
<?xml version="1.0" encoding="utf-8" ?>
<events>
</events>
I add events to xml through code. Final structure of the xml file is the following
<?xml version="1.0" encoding="utf-8" ?>
<events>
<event Name="Some Name">
<startDate>20.03.2010</startDate>
<endDate>29.03.2010</endDate>
</event>
</event>
Now here's my problem. If I update the app and deploy it with Click Once and the app updates it self, I lose the list because the new file is empty. Any workaround this?
Here's how I add the Data:
var xDocument = XDocument.Load(@"Data\Events.xml");
xDocument.Root.Add(new XElement("event", new XAttribute("name", event.Name),
new XElement("startDate", startDate),
new XElement("endDate", endDate)
)
);
xDocument.Save(@"Data\Events.xml");