Keeping settings across versions?

S

Sin Jeong-hun

I used the settings class that VS.NET automatically generates to save
some app settings, simply because it is the easiest way. But the
problem is, even though the settings class wasn't changed (no fileds
are modified) each time I change my app's version slightly (like 0.1.0
to 0.1.1) all the settings are gone. Is it possible to keep settings
across versions as long as teh settings class isn't modified?
 
S

Sin Jeong-hun

I used the settings class that VS.NET automatically generates to save
some app settings, simply because it is the easiest way. But the
problem is, even though the settings class wasn't changed (no fileds
are modified) each time I change my app's version slightly (like 0.1.0
to 0.1.1) all the settings are gone. Is it possible to keep settings
across versions as long as teh settings class isn't modified?

There's no way to avoid this? It's really annoying that all settings
are gone if I change the version slightly (like 1.0.0-> 1.0.1). Do I
have to create my own way to save and load settings instead of using
VS.NET's built-in settings architecture? Please give me any advice.
 
R

Rob Lancaster

S

Sin Jeong-hun

Have a look at ApplicationSettingsBase.Upgrade()

http://msdn2.microsoft.com/en-us/library/system.configuration.applica...

Rob

Thank you. I guess Upgrade() should be called once the version has
chaged, and there seems to be no way to get whether the settings file
for this version of the application is just created or not (i.e. first
run), I added an entry "FirstRun" with default value = true and added
the following code at the beginning of the application.

if (Properties.Settings.Default.FirstRun)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.FirstRun = false;
}
Now everything seems to work as I expected.
 
P

Phil S

I had the same problem, and Jeong-hu's solution worked except for one small detail:

I allow users to reset the application settings to default, where I call Settings.Reset(). However, this does not remove older versions of the settings, and as a result, they end up upgrading the old settings again.

When calling Reset(), it is also necessary to set FirstRun to false again, and Save().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top