0
votes

I have a Windows Phone app that relies on an XML data file that comes packaged with the app. When the app is ran the first time on a phone, I load the file into isolated storage. Once the file is loaded into isolated storage, the app uses the isolated storage version of data. In the next version of my app (the Marketplace update), the XML file will have more elements, how do I update the data file once per app update (new version on the Marketplace)?

I thought I could change the file name in the isolated storage, but that would leave trash behind. I could also check for exceptions when I load the XML file, but are there any other, more elegant ways? I do not want to check for the old file in the isolated storage every time my app runs.

The ideal scenario would be to put a piece of code that would be executed once when the new version of the app is loaded onto the phone, is there a way to do that?

3
If the XML file comes packaged in the app, when you update the app (and the new package will have the new XML file), it will just be there. Not really sure I understand the issue.Shahar Prish
Good point. The first time the app is ran, I read the XML file into isolated storage, and then the app only uses the file in the isolated storage.Eugene
Unless by 'app update' at the end of the first paragraph, you don't mean a Marketplace update, but app launch or something?Shahar Prish
Sorry -- still not entirely sure about what you mean... What does 'app update' at the end of your first paragraph mean? A Marketplace update? If so, just read the XML file again and overwrite the file in iso storage. If you mean something else (every time the app launches), then read the file from the web, and overwrite the XML you have in iso-storage.Shahar Prish
Marketplace update. How do I read the XML file once when the app is updated? Is there a way to do that? I don't want to read the file into isolated storage every time the app starts.Eugene

3 Answers

1
votes

To my knowledge there isn't an "out of the box" event that will run a single time at the first run of an app after it was installed/updated.

You'd have to flag the run your self, like you are already stating (save the current version, compare version at each run of the app to see if app was updated!)

0
votes

I think I now understand what you want.

  1. Add the XML file as a resource.
  2. Use GetResourceStream to get the content of the XML.

Note that the name for the resource would be something like /DllName;component/Folder/ResourceName

0
votes

Here is what I did:

In the constructor method of my DataLayer class, I added the following code:

private bool AppIsOld
{
    get
    {
        string storedVersion = GetStoredAppVersion(); //stored previously "seen" version
        string currentVersion = GetCurrentlyRunningAppVersion();
        return !(storedVersion == currentVersion);
    }
}


private string GetCurrentlyRunningAppVersion()
{
    var asm = Assembly.GetExecutingAssembly();
    var parts = asm.FullName.Split(',');
    return parts[1].Split('=')[1].ToString();
}

And then I run the following check:

if (AppIsOld)
    RefreshResources(); //do whatever to refresh resources

The code for GetCurrentlyRunningAppVersion() function is taken from here.

This solution is not what I had in mind because it runs every time the class constructor is called while I wanted something that would run once upon version update.