tags:

views:

52

answers:

2

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

If it is an option I would suggest that you don't include the Events.xml as a part of the project. If you did this, you could:

  1. Check to see if it is there before you load it.
  2. If it is not there, write out an empty one.

If Events.xml is not a part of the project, Click Once won't overwrite it on updates.

Software.Developer
if I create the file manually through code and then update the app i still lose it because the update doesn't update the .exe file. instead it creates a new folder and puts the new updated files there.
Robert Iagar
In that case I would recommend saving this Events.xml file toEnvironment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Software.Developer
i'll try it. thanks for the tip.
Robert Iagar
A: 

I figured out my own problem.

Here's my method. Create a folder @C:\Program Files\<MyApp>\Data\ add the Events.xml file there when the app runs for the first time and I have the file there always.

The only draw back is that user needs to delete the folder manually on uninstall.

Click Once does not install the app @C:\Program Files\<MyApp>\ by default. It installs to @C:\Users\<Username>\AppData\Local\Apps\2.0\ (under Windows 7).

Any workaround this?

Robert Iagar