Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having .NET applications "remember" preferences, etc?

Tags:

c#

.net

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.

like image 568
Bhaxy Avatar asked Dec 20 '11 21:12

Bhaxy


1 Answers

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            
}
like image 193
Anthony Shaw Avatar answered Oct 12 '22 23:10

Anthony Shaw