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
2009-11-05 05:14:15
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
2009-11-05 23:15:02
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
2009-11-06 00:34:11