Connecting Tech Pros Worldwide Help | Site Map

How to maintain user.config settings when upgrading?

  #1  
Old August 10th, 2006, 04:45 PM
davepkz@hotmail.com
Guest
 
Posts: n/a
I have a basic question about managing user.config settings:

In my C# app, I save the user's preferences to the config file. But
each time I release a new build of the app, something in .NET creates a
new folder (named for the build number) in Documents And Settings. The
result is the users lose all their settings and have to start over.

What is the standard way to allow users to maintain their settings when
they get a new version of a .NET app?

thanks
Dave

  #2  
Old August 10th, 2006, 09:35 PM
Mike Lowery
Guest
 
Posts: n/a

re: How to maintain user.config settings when upgrading?



<davepkz@hotmail.comwrote in message
news:1155225149.646271.291150@75g2000cwc.googlegro ups.com...
Quote:
>I have a basic question about managing user.config settings:
>
In my C# app, I save the user's preferences to the config file. But
each time I release a new build of the app, something in .NET creates a
new folder (named for the build number) in Documents And Settings. The
result is the users lose all their settings and have to start over.
>
What is the standard way to allow users to maintain their settings when
they get a new version of a .NET app?
You could store them in a different file or use the registry.


  #3  
Old August 11th, 2006, 12:35 AM
Carl Daniel [VC++ MVP]
Guest
 
Posts: n/a

re: How to maintain user.config settings when upgrading?


<davepkz@hotmail.comwrote in message
news:1155225149.646271.291150@75g2000cwc.googlegro ups.com...
Quote:
>I have a basic question about managing user.config settings:
>
In my C# app, I save the user's preferences to the config file. But
each time I release a new build of the app, something in .NET creates a
new folder (named for the build number) in Documents And Settings. The
result is the users lose all their settings and have to start over.
>
What is the standard way to allow users to maintain their settings when
they get a new version of a .NET app?
Here's the way I do it - ClickOnce does something similar automatically.
You need to make use of the SettingsBase.Upgrade method.

Add a Setting to your project called ApplicationVersion, then use code like
the following in the startup of your applicaiton:

System.Reflection.Assembly a =
System.Reflection.Assembly.GetExecutingAssembly();
Version appVersion = a.GetName().Version;
string appVersionString = appVersion.ToString();

if (Properties.Settings.Default.ApplicationVersion != appVersion.ToString())
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.ApplicationVersion = appVersionString;
}

-cd


  #4  
Old August 12th, 2006, 06:35 PM
davepkz@hotmail.com
Guest
 
Posts: n/a

re: How to maintain user.config settings when upgrading?



This suggestion worked perfectly. Thanks.
Dave


Carl Daniel [VC++ MVP] wrote:
Quote:
Here's the way I do it - ClickOnce does something similar automatically.
You need to make use of the SettingsBase.Upgrade method.
>
Add a Setting to your project called ApplicationVersion, then use code like
the following in the startup of your applicaiton:
...
Closed Thread