Skip to main content

In Windows Phone 7 there are two ways to store values State & IsolatedStorageSettings which have their various pro’s and con’s. I prefer to use the IsolatedStorageSettings for most scenarios but this tip will apply to both, so when you see the code referring to one it will work on both.

Very simply the first setting you should store is one called version (or similar) and should have a version indicator. In short it tells you what version of the settings you are working with!

IsolatedStorageSettings.ApplicationSettings["version"] = "1";

Having this field has two advantages for you, first it gives you a very simple way to check if you have settings available & if it is not, then your app is running for the first time.:

if (IsolatedStorageSettings.ApplicationSettings.Contains("version"))
{
    // do something with settings
}

The other advantage is that when you update your application you can upgrade settings easily. 

if (IsolatedStorageSettings.ApplicationSettings.Contains("version"))
{
    switch ((int)IsolatedStorageSettings.ApplicationSettings["version"])
    {
        case 1:
        {
            // upgrade version setting and add missing settings or change existing settings
            break;
        }
        case 2:
        {
            // normal reading of settings
            break;
        }
    }
}
Even if you never use it for upgrades, at least it is there for a simple check and if one day you need it - you are ready to go!