-1

The question is quite simple: I have developed a WinForms application using C# .Net 4.0. I want to implement a form where a user can set the settings of the application, like short keys, connection string, server name, financial year etc.

Once user has set all the settings, these settings would be available even after user closes the application and then open it again. Like in many video players, we use hot keys and set keys according to our needs. Every time we run our media player, the settings are preserved, unless we change them again. This is what I want in my application.

Well, one approach hit in my mind. That is to use caching. Actually, I dont want to store this information in my database. It would be an extra overhead. So guys what is the best approach to achieve the criteria I described? If caching, then why? What are the advantages and disadvantages?

Any help is appreciated.

John Willemse
  • 6,608
  • 7
  • 31
  • 45
user2109843
  • 67
  • 1
  • 1
  • 6

3 Answers3

4

There is a built in feature for what you are looking to do - the Settings file.

See Using Settings in C# on MSDN:

The .NET Framework 2.0 allows you to create and access values that are persisted between application execution sessions. These values are called settings. Settings can represent user preferences, or valuable information the application needs to use. For example, you might create a series of settings that store user preferences for the color scheme of an application. Or you might store the connection string that specifies a database that your application uses. Settings allow you to both persist information that is critical to the application outside of the code, and to create profiles that store the preferences of individual users.

Though written for .NET 2.0 and Visual Studio 2005, it is still relevant.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
4

You have many options.

  • You can use App.Config
  • You can create a flat text file where all the settings could be stored. (Use delimiters to separate key and value.)
  • You can use an XML file to save all the setting.

Most of the program used to store the settings in %AppData% folder.

Community
  • 1
  • 1
PawanS
  • 7,033
  • 14
  • 43
  • 71
2

Why are a few bits and bytes of settings "overhead"? Also what do you think caching is going to solve? Caching is runtime, so when the user closes the application the settings are lost.

You can store the settings in any way you like. Database, application settings, or roll your own format.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272