How to upgrade application version and not loose user application settings

by Miha Markič 10. December 2005 00:08

If you have been using or considering using new application settings feature in VS 2005 you might be wondering how not to loose user settings when you increment assembly version. The thing is that user settings are not automatically upgraded and you loose them if you don't do anything. Note that you loose only user settings while application settings are stored in app.config (or web.config) and are always there. The answer has two parts:

  1. If you use ClickOnce deployment it will take care of upgrading.
  2. If you don't use ClickOnce then you have to call Update method of ApplicationSettingsBase derived class (that is normally called Settings and created for you by the IDE). The acutall call would be something like

         Settings.Default.Update(); [C#]
         My.Settings.Update()   [VB]

But how do you know when to call the Update method? This is a trick I learned from a blogger I can't remember right now, I think he is a MS employee (sorry):

  1. Define a user settings called i.e. UpdateRequired of type bool (the easiest way is through IDE). Make sure its default value is true.
  2. At the start of the application type this code:

      if (Settings.Default.UpdateRequired)
      {
         Settings.Default.Update();
         Settings.Default.UpdateRequired = false;
      }

So the Update will be called only after the version changes and only one time (since you disable further updates by setting UpdateRequired = false until version changes - when the property regains default value of true).

Have fun, application settings are worth exploring.

Tags:

.net

Comments (3) -

Bill
Bill
12/13/2005 7:03:42 PM #

I don't know how you foudn this -but totally excellent post!

Reply

Miha Markic
Miha Markic
12/14/2005 11:44:19 AM #

I was forced to look for a solution Smile

Reply

Desiderius
Desiderius
8/6/2006 12:03:49 PM #

Thanks for the tip.  However it would seem that the code actually required at the start of the application is:

if (Settings.UpdateRequired)
{
    Settings.Upgrade();
    Settings.UpdateRequired = false;
}

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Miha Markic

About me
Righthand
 
Microsoft MVP
 
Developer Express' DXSquad
INETA Country Leader for Slovenia
INETA Country Leader for Slovenia

Slovene Developer Users Group Lead
Friends of Red-Gate
LLBLGenPro Partner

Miha currently works as a free lance consultant and software developer specialized in .net area.
He graduated in Computer and information science at the University of Ljubljana, Slovenia. He has accumulated experience in various programming languages such as Java, Visual Basic 3-6 (MCP), Visual C++, Delphi, C# and VB.Net through years.
He has experience in practically all (technical) stages of project development, including planning, framework development, user interface, business processes, as well as testing and documenting. He has worked on big and small projects in Slovenia and abroad (e.g. participated in completing level 3 IS for the Nucor steel plant, Hertford, USA).
Currently he enjoys programming in .net environment using C#. Since 2000 he has been active in Developer Express' DX Squad and has been ECDL trainer and tester. He also gives lectures on conferences and other events in Slovenia.

Month List

Tag cloud

Most comments

Paulius Paulius
1 comments
us United States
Meh Meh
1 comments
us United States
bart dm bart dm
1 comments
nl Netherlands

RecentComments

Comment RSS