This is sort of a "newbie" question, but I was wondering what the best way is to have .NET applications store user-configured data between runs.
For example, if I wanted to create a list of preferences for my application, what would be the best way to store those preferences, so that they take effect for the next time I run the application? What file type should I store it as? Where should I store it? I want the application to take care of all of that, so the user doesn't have to worry about it.
I'm assuming you're referring to a Windows Application?
There is a Settings class built into the application that you can use. The only thing that you'll want to take care with is on application upgrades, but you can check if the settings need to be upgraded and run the appropriate method
Here is an article that walks through creating these, http://msdn.microsoft.com/en-us/library/25zf0ze8.aspx
Then when the application is upgraded (say with OneClick Deployment) you need to call this block of code, or else your settings will be reverted to default
if (Properties.Settings.Default.CallUpgrade)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.Reload(); // to activate the settings
Properties.Settings.Default.CallUpgrade = false;
Properties.Settings.Default.Save();// to save the new value of CallUpgrade
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With