-1

Can anyone provide a best-practices example for where to store user preferences for a C# Windows app?

So far I've heard a number of options:

  • Some people are saying to store it in SQLite. Is SQLite bundled with .NET 2.0 and immediately available for use to me?

  • Others have said to use the built-in Application Settings... but I've heard that the per-user settings here disappear if you upgrade the app (an obvious problem).

  • I've also considered just storing it in a .xml file somewhere on disk... but where it the "correct" place to store that .xml file for the user?

Keith Palmer Jr.
  • 27,666
  • 16
  • 68
  • 105

2 Answers2

2
  • SQLite is not included with .NET2, but you could ship it with your application
  • The built-in settings system works fine for simple apps - you do need to add a couple of lines of boilerplate to deal with version changes but it's not complicated.
  • You could put your xml file here:

    Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData)

There is a lot of 'it depends' about your question, as you don't say how much of what types of data you need to store, nor if you have any other reasons to care where it goes.

Will Dean
  • 39,055
  • 11
  • 90
  • 118
  • Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) ... Where does this end up? Is this compatible with UAC on Windows 7 and Windows Vista where a lot of program data locations are off limits for writing/modifying files? – Josh G Apr 28 '11 at 12:49
  • @Josh G On this Win7 box (not on a domain), it's at C:\Users\\AppData\Local. I can't think of any 'data' special folder which would be a problem with UAC, but LocalApplicationData definitely isn't restricted, and nor is CommonApplicationData – Will Dean Apr 28 '11 at 16:54
-1

Storing user application settings in isolated storage seems to be a best practice.

http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage(v=vs.80).aspx

Storing settings as an xml file is perfectly fine.

Ryan Bennett
  • 3,404
  • 19
  • 32
  • Isolated storage is for SilveLight and the like. Storing in a custom XML file is not as good as using the Settings. Conventions etc. – H H Mar 22 '11 at 18:51
  • I distinctly remember while studying for the App Dev Foundations test that they recommended Isolated storage - this was before Silverlight even existed. – Ryan Bennett Mar 23 '11 at 16:24
  • 1
    Isolated storage is NOT only for Silverlight. It is used extensively for Silverlight because the file system is not available, but isolated storage is also an option for standard .NET applications. – Josh G Apr 28 '11 at 12:51