using System.Configuration;
You read and write them like this:
The tricky part is that every time you update your application version number, these settings are left behind and it creates a new set for you. How do you get around such a problem? By using a couple of the more obscure features of Properties.Settings.Default.internalValue = Properties.Settings.Default.MyNamedSetting;
// modify your internal value.Properties.Settings.Default.MyNamedSetting = internalValue;
First, you need a way to detect when it's a new version. You can do that by creating a boolean settings entry named something like FirstRun with a default value of true. You can tell if it's your very first time to run the application at a particular version number because it will have the default value of true. Then you can set the value of FirstRun to false. By using the special built-in Upgrade() function, and saving the results, you can import your previous data just like this:
There. Now you have a system that automatically detects version bumps, and saves all your special settings from one version to the next.if(Properties.Settings.Default.FirstRun)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.FirstRun = false;
Properties.Settings.Default.Save();
}
No comments:
Post a Comment