Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Save user settings in .Net Windows application

Posted on 2008-06-14
7
Medium Priority
?
4,246 Views
Last Modified: 2013-11-07
I am writing a Windows application using C#.Net.  What is the preferred method for storing user settings/preferences without writing to the registry?
0
Comment
Question by:ktmedlin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21787608
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
0
 

Author Comment

by:ktmedlin
ID: 21787634
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.
0
 
LVL 11

Accepted Solution

by:
Anurag Agarwal earned 2000 total points
ID: 21787669
You can use a flat file that is a text file for storing the user specific data. In this flat file you can put settings like this

[UserId=""]
Maximize=1;
Toolbar=0;
---
---

[UserId=""]


When you read this text file you can read the key from 0 to 1 less then index of =.
& fopr reading the  value 1 + index of = to 1 less then index of ;

Another way is to use a XML file.
Make a empty xml file with default values with nodes

<UserSettings UserId="">
   <Maximize>1</Maximize>
   <ToolBar>0</ToolBar>
</UserSettings>

Now read this xml file in your code through XMLDocument & get the required values.

Don't use settings.settings & App.config for this as they contain application specific settings not user specific.


Anurag
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:Dauhee
ID: 21788446

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>
0
 
LVL 1

Expert Comment

by:cherrera2001
ID: 21808739
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.
0
 

Author Closing Comment

by:ktmedlin
ID: 31467295
Im going with the XML file option.  Thanks to all the experts for the comments.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question