3

I have a Win Form app that stores some per user settings in a UserSettings.Settings file. This has worked well so far, however it seems that the Settings file gets "reset" when ever I release an update. Which I do through ClickOnce.

Is this the expected behavior?
Can I control if fields in the Settings file get overwritten?
Is there a better way I should store user settings?

Thanks

Refracted Paladin
  • 12,096
  • 33
  • 123
  • 233

4 Answers4

4

When you release an update your updated app should call ApplicationSettingsBase.Upgrade Method to move values from the previous version. Here is a similar question: Automatically "upgrade" user settings from previous version of app.config file?

Keep in mind that you should call the above method only once so you probably will have to store whether you have already called Upgrade or not in the settings too and do something like this:

if(!Settings.Default.Upgraded)
{
   Settings.Default.Upgrade();
   Settings.Default.Upgraded = true;
   Settings.Default.Save();
}

Another possible solution is to store settings in a folder that does not depend on the application version. In that case you will not lose values and there will be no need to upgrade settings between versions.

Community
  • 1
  • 1
Giorgi
  • 30,270
  • 13
  • 89
  • 125
  • 1
    this is the correct answer; I was almost going to write the same :) – Davide Piras Sep 06 '11 at 19:38
  • Just to be clear; I do this with `ClickOnce` deployments or no. I was gathering, based on answers here and related, that `ClickOnce` did something like this for you, no? – Refracted Paladin Sep 08 '11 at 03:51
  • This is why I hate bounty's....anyway, is the proper etiquette for me to start another thread as this did not fix my issue. My Setting's still reset even using the `.Upgrade()` What am I missing? – Refracted Paladin Sep 16 '11 at 14:56
  • @ReractedPaladin: Do you call save after calling Upgrade? I haven't used ClickOnce so I don't have any experience with that. – Giorgi Sep 16 '11 at 16:36
  • @Giorgi: Yeah, I do. I pretty much have a setup identical to your answer except my variable was `NeedsUpgrade`. This is insanely frustrating, I have a post at MSDN as well and they are even less help then SO so far. Thanks for the help though, much appreciated. – Refracted Paladin Sep 22 '11 at 02:11
2

Where are you saving the .Settings file? It probably shouldn't be included in the installation directory with your executable. Try moving it to the user's application data directory:

http://blog.kowalczyk.info/article/Getting-user-specific-application-data-directory.html

Good luck!

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
  • I wasn't saving it anywhere, just letting the app save it to wherever it does... :( I feel stupid even saying that. I didn't realize I could control where it saves. – Refracted Paladin Sep 02 '11 at 21:55
1

Are you simply using the built in Application Settings with ClickOnce?

If so then you just have to set the Scope to User in the settings editor and the setting will be merged on upgrades as described here

Just as each version of a ClickOnce application is isolated from all other versions, the application settings for a ClickOnce application are isolated from the settings for other versions as well. When your user upgrades to a later version of your application, application settings compares most recent (highest-numbered) version's settings against the settings supplied with the updated version and merges the settings into a new set of settings files.

BrandonAGr
  • 5,827
  • 5
  • 47
  • 72
0

Under Windows Vista/7 It gets saved into:

C:\Users\USERNAME\AppData\Local\MANUFACTURER_NAME\

and

C:\Users\USERNAME\AppData\Roaming\MANUFACTURER_NAME\

im pretty sure it gets saved into the application data under xp too.

Your settings keep resetting because the new version uses a different folder. Check it.

Qqbt
  • 802
  • 2
  • 8
  • 33