views:

55

answers:

1

I am deriving from ApplicationSettingsBase to store our users settings, however when the build number gets incremented the app uses a new settings folder, and so the old settings are lost. What is an appropriate way to deal with the situation of shared settings over different build numbers.

+3  A: 

Have a User setting called Upgraded, boolean that defaults to false. Then do a check:

  if (!Properties.Settings.Default.Upgraded)
  {
    Properties.Settings.Default.Upgrade();
    Properties.Settings.Default.Upgraded = true;
    Properties.Settings.Default.Save();
    Trace.WriteLine("INFO: Settings upgraded from previous version");
  }

This will upgrade the settings from the previous version if it's the first run of the new version.

mrnye
i used this code in my settings objects constructor public MySettings() : base() { if (this["Upgraded"] == null) { //this is the initial load, so upgrade the settings this.Upgrade(); this.Upgraded = true; } }works great. cheers.
Aran Mulholland
In case you were wondering too, the upgrade method will take whatever the previous version settings were and override the current version settings. Hence why you need a flag, rather than just upgrade every time.
mrnye