Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom settings from My.Settings reset every time new install goes out 1

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Hello all,

I have several custom settings such as LastFormLocation and LastInputFolder which I maintain at the user level for my application. Every time I send out a new Installer these settings are re-initialized.

Custom user settings are saved in a path like the following:
Code:
C:\Documents and Settings\glw2\Local Settings\Application Data\Valmont\MarisaInterface.vshost.ex_Url_h224bxompltlxk4ezksikdmyen1xtnej\1.3.0.0
where 1.) Valmont is the CompanyName, 2.) MarisaInterface.vshost.ex_Url..etc is the assembly name cobbled together with a unique name assigned by Microsoft somewhere and 3.) 1.3.0.0 is the current build version.

I need to retain the custom settings across versions. How do I do that? Surely I don't have to attempt to navigate the path above do I? Thanks in advance for any ideas and/or suggestions!
 
Found this ClientSettings FAQ: which discusses all of this and more.

Here is the part where the author discusses my specific questioin above.

Q: Why is there a version number in the user.config path? If I deploy a new version of my application, won't the user lose all the settings saved by the previous version?

A: There are couple of reasons why the user.config path is version sensitive. (1) To support side-by-side deployment of different versions of an application (you can do this with Clickonce, for example). It is possible for different version of the application to have different settings saved out. (2) When you upgrade an application, the settings class may have been altered and may not be compatible with what's saved out, which can lead to problems.

However, we have made it easy to upgrade settings from a previous version of the application to the latest. Simply call ApplicationSettingsBase.Upgrade() and it will retrieve settings from the previous version that match the current version of the class and store them out in the current version's user.config file. You also have the option of overriding this behavior either in your settings class or in your provider implementation.

Q: Okay, but how do I know when to call Upgrade?

A: Good question. In Clickonce, when you install a new version of your application, ApplicationSettingsBase will detect it and automatically upgrade settings for you at the point settings are loaded. In non-Clickonce cases, there is no automatic upgrade - you have to call Upgrade yourself. Here is one idea for determining when to call Upgrade:

Have a boolean setting called CallUpgrade and give it a default value of true. When your app starts up, you can do something like:

if (Properties.Settings.Value.CallUpgrade) {
Properties.Settings.Value.Upgrade();
Properties.Settings.Value.CallUpgrade = false;
}

This will ensure that Upgrade() is called only the first time the application runs after a new version is deployed.
 
very usefull thanks.

I was told by MS that it would overwrite the previous settings.

But I don't use them much and especially not for usersettings.

have a twinkle.

Christiaan Baes
Belgium

"My old site" - Me
 
In case it wasn't clear in my sample code posted above, CallUpgrade is itself a user level setting with a value of True. The code then resets it and it won't be changed until a new version is installed, in which case it will then be reset to True causing the code to execute again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top