How to save XML file before update?

Posted by Robert Iagar on Stack Overflow See other posts from Stack Overflow or by Robert Iagar
Published on 2010-03-11T18:36:48Z Indexed on 2010/03/11 18:39 UTC
Read the original article Hit count: 205

Filed under:
|
|

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");

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf