4

Pardon my ignorance, but I've never really developed Windows applications. How do you store user settings? Is an embedded database the preferred method?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Esteban Araya
  • 29,284
  • 24
  • 107
  • 141
  • 2
    This [SO Question answers](http://stackoverflow.com/questions/26369/what-is-the-best-way-to-store-user-settings-for-a-net-application) it quite well. – Michael La Voie Jun 03 '09 at 18:44

4 Answers4

9

I think you are looking for user settings:

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.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
2

It depends on what kind of settings. There are a variety of methods from embedded databases (like SQLite) to XML files, to the Registry.

  • If the settings are very few, the registry often makes sense.
  • If the settings are more complicated, and need to be hand edited, you can use XML files or JSON.
  • If the settings are complex and do not need hand editing, an embedded database like SQLite, .NetBtree, or BerkelyDB .NET are good choices.
Christopher
  • 8,815
  • 2
  • 32
  • 41
  • Another consideration is versioning; any real-world application will acquire more settings as it evolves. Older versions of the application should tolerate newer versions of the settings (ignoring newly added settings) and newer versions of the application should tolerate older versions of the settings file (using sensible defaults for the missing parameters) – Peter Mortensen Jul 12 '14 at 15:49
1

Use Blane's Pegasus Library (http://pegasus.codeplex.com/).

You could use his XmlSerializationHelper class which makes it a snap to turn objects into XML and vice versa.

Or you could use Isolated Storage (I would provide a link to MSDN if I wasn't a new user and restricted to one hyperlink per post). If you use IsolatedStorage, consider using Blane's IsolatedStorageHashtable class.

mkmurray
  • 2,434
  • 3
  • 21
  • 22
1

It all depends on what size of an application you are building. If you are on something simple, let's say, "family shopping list", you can store the settings in a good old plain text file.

If you are building something bigger, for example a "classmate notifier" you can use an XML file, or some kind of other resource.

For any bigger application you should use some kind of relational database, for storing user data.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Peter Stegnar
  • 12,615
  • 12
  • 62
  • 80
  • As posted by others, .NET 2.0 Settings is even more simple than a text file as there is no right hand to left hand code to deal with. – Nate Jul 13 '09 at 20:55