Link to home
Start Free TrialLog in
Avatar of ktmedlin
ktmedlin

asked on

Save user settings in .Net Windows application

I am writing a Windows application using C#.Net.  What is the preferred method for storing user settings/preferences without writing to the registry?
Avatar of Anurag Agarwal
Anurag Agarwal
Flag of India image

One way to put them in memory by Creating a singleton class & store the user settings.

Another way (Recommended) is to store this into database tables.

Anurag
Avatar of ktmedlin
ktmedlin

ASKER

The user's settings must be stored on the hard drive (not in memory) so that the same settings can be used when the user has closed and reopened the app.  Storing settings in a database is not an option.  Need to use a file of some type but don't know what kind.  I assume XML would be the best solution and I have heard of Settings.settings and App.config but I don't know which one to use or how to use them.
ASKER CERTIFIED SOLUTION
Avatar of Anurag Agarwal
Anurag Agarwal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

READ SETTINGS:
dsConfig = New DataSet
dsConfig.ReadXml('c:\file.xml')
msgbox dsConfig.Tables(0).Rows(0).Item('mydatafield')

WRITE SETTINGS:
dsConfig.Tables(0).Rows(0).Item('mydatafield') = 'changed value'
dsConfig.AcceptChanges()
dsConfig.WriteXml('c:\file.xml')

XML FILE:
<?xml version="1.0" standalone="yes"?>
<Settings>
  <MYTABLE>
    <mydatafield>Hello there this is a setting</mydatafield>
    <anotherfield>bla bla Bla</anotherfield>
  </MYTABLE>
</Settings>
One possible solution is if you saved the user settings in an object, to serialize the object to an xml file. This allows for a clean and easy way to save and retrieve the data. There is also an msdn article on different ways to approach this here: http://msdn.microsoft.com/en-us/library/ms973902.aspx.
Im going with the XML file option.  Thanks to all the experts for the comments.