views:

43

answers:

4

I'm using .NET user settings feature and I'm facing a problem.

When the application is uninstalled, then installed back, the user settings are lost.

I understand it's by design, and I want to be able to give the choice to the user in the installer.

Could you please give me some pointers to articles or documentation that will helps me?

Thanks a lot

A: 

You could possibly write the settings you wish to save out to the registry or write them as an XML file to a location that won't be impacted by the uninstall.

Chuck
Could you point me to article explaining how to create a custom persistance provider for them ?
Pierre 303
I don't have anything bookmarked, but a quick google search turned up this http://www.java2s.com/Code/CSharp/Windows/Savevaluetoregistery.htm
Chuck
Why this has been downvoted without an explanation?
Pierre 303
A: 

If you want to keep using User Settings i would suggest writing a custom installer class, and implement the onUninstalling method, to go find the file and copy it to another location known to the onInstall method of your custom installer. So that the next time the installer runs it could find the file.

unclepaul84
Why this has been downvoted without an explanation?
Pierre 303
A: 

I don't think you want to actually persist data on the users machine after an uninstall. Leaving files around is an evil practice, a big no-no. You should expose a feature in the application itself to either export those settings to a location of their choice and to then import it again after re-installing the app or to synchronize those settings onto a server so they're automatically available upon re-install, etc. On an uninstall you should leave no trace behind.

justin.m.chase
+1 mucho agreo!
Lucas B
Read my question again: " I want to be able to give the choice to the user in the installer". I want to give the choice.
Pierre 303
+1  A: 

.NET User Settings are not removed on uninstall. In fact the settings of all previous versions of the software are preserved in Local Settings directory.

When the new version is installed, a new version of the settings is created and default settings are used.

To ensure your application will merge new settings with previous configuration, you have to call Settings.Default.Upgrade() method.

This is the blog post that let me find the solution.

So the solution is to manually remove settings on uninstall if we don't want to preserve them. Since what I needed was preserving previous settings, all I do now is creating a new setting called UpgradeRequired with true has the default value, then add this code at application startup:

if (Properties.Settings.Default.UpdateRequired)
{
    Properties.Settings.Default.Upgrade();
    Properties.Settings.Default.UpdateRequired = false;
}
Pierre 303