Our product has several user-defined settings, which to date have been stored using the project’s Settings variables, e.g.
public string MySetting {
get { return Settings.Default.MySetting; }
set {
Settings.Default.MySetting = value;
Settings.Default.Save();
}
}
That works fine – but it has the unfortunate characteristic that if you uninstall the app and reinstall a newer version (no direct upgrade path exists – don’t ask), all the settings are lost.
I can think of a few ways of achieving this, but they all seem a bit kludgy to me. What do you think is the neatest way of preserving user-defined application settings between uninstalling & reinstalling?
On Windows, there are two ways I can think of that could accomplish this. The first is simply storing an XML/INI/JSON/whatever file in the user’s AppData folder. This would place the file out of the path for the application which means you could easily go get it again. You can find the AppData folder like so:
The other place that would be good for this type of data is the registry. The .NET framework has pretty good support for doing this. There’s a lot of documentation out there on MSDN and other places to help you get started.