3

At first I had some userdefined settings stored in my app.config file, under appSettings. These are properties the user can change during runtime. The first problem I've got is when I deploy my application with ClickOnce it overwrites the app.config file and the user has lost his personal settings.

Then I moved the properties to the settings.settings file (= usersettings section in app.config) as I found on the internet that this section doesn't get overwritten when deploying with ClickOnce. Nah, it does.. Settings.Settings properties are:

  • Build action = content
  • Copy to = Do not copy

So how can I accomplish that my user's personal settings are not overwritten, either in the app.config file or the settings.settings file. Or is there another way and am I doing it wrong?

Thx!

PitAttack76
  • 2,120
  • 5
  • 31
  • 44

1 Answers1

6

This method copies the settings from the previous installation when deploying a new version of the application with ClickOnce. So any user defined settings that the user made will be copied and thus available after the update. I tested this and it works for me.

public static void UpgradeUserSettings()
{
  if (Settings.Default.upgradeRequired)
  {
    Settings.Default.Upgrade();
    Settings.Default.upgradeRequired = false;
    Settings.Default.Save();
  }
} 

ApplicationSettingsBase.Upgrade Method MSDN

other question on StackOverflow

Community
  • 1
  • 1
PitAttack76
  • 2,120
  • 5
  • 31
  • 44
  • 3
    where should I embed this code in my application,actually I put this code in Program.cs before running the application and didn't worked ?!! – franchesco totti Oct 18 '13 at 20:08
  • I'm kind of in the same place @franchescototti. This looks like an elegant solution, but I've no idea where to put it... – RubberDuck Jul 31 '15 at 12:24