Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

how to read/write settings (using .ini, xml, whatever)?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
titan nyquist - 30 May 2007 13:49 GMT
I want to read/write user settings.  I thought about using .ini
or .xml files.  Are there classes in c# to handle this?  The stuff I
find on the 'net seems old.

Titan
Andy - 30 May 2007 13:53 GMT
> I want to read/write user settings.  I thought about using .ini
> or .xml files.  Are there classes in c# to handle this?  The stuff I
> find on the 'net seems old.

If you're using vs 2005, you can open the Project properties, click on
the Settings tab.  You should get a link offering to create settings.
Put application and user settings in there.  YOu can then use them via
Properties.Resources.Default.

HTH
Andy
titan nyquist - 30 May 2007 14:13 GMT
With that, can create a GUI to let the user change these settings?
How are the saved from one session to the next (from one run of the
program to the next time)?
Moty Michaely - 30 May 2007 14:14 GMT
> > I want to read/write user settings.  I thought about using .ini
> > or .xml files.  Are there classes in c# to handle this?  The stuff I
[quoted text clipped - 7 lines]
> HTH
> Andy

Hi,
What kind of settings do you need to store?

Moty
titan nyquist - 30 May 2007 14:21 GMT
> What kind of settings do you need to store?

Just numbers and strings.  Without getting into the description of the
program, the user has settings he/she may want to change.  For
example, there are delay settings in milliseconds.  It might be set to
1,000 (one second), and the user may want to change that to 10,000
(ten seconds).  There's also folder location settings for files, and
many other things.

I was going to put them into an .ini file, and have the user update
the file, and have the program read the file.  It is what I am working
on right now.  But, is there a better way?

Titan
titan nyquist - 30 May 2007 14:37 GMT
I just thought of a problem... I want the user to be able to change
settings for multiple instances of this program.  It will be run on
multiple computers.  So, it would be a hassle to have the user go in
and modify the settings on each program.  What would be easiest, would
be to have the settings inside a .ini file (text file) that the user
modifies only once, and then copies to each instance of the program.

So, that's what I want do to.  Read in an .ini file.  Sorry for
jumping around.  This is not typically what a software dev. would be
wanting to do.

So, is there a class in c# to read in .ini files?

~Titan
Mark Rae - 30 May 2007 14:55 GMT
>I just thought of a problem... I want the user to be able to change
> settings for multiple instances of this program.  It will be run on
[quoted text clipped - 8 lines]
>
> So, is there a class in c# to read in .ini files?

I don't believe there's anything built-in...

I tend to use XML documents for this, using the System.Xml namespace - this
would allow you to do the copying etc...

However, if you *really* want to use .ini files, you could do it fairly
easily with a couple of API calls:

http://www.pinvoke.net/default.aspx/kernel32/GetPrivateProfileString.html
http://www.pinvoke.net/default.aspx/kernel32/WritePrivateProfileString.html

Signature

http://www.markrae.net

Andy - 30 May 2007 16:39 GMT
> I just thought of a problem... I want the user to be able to change
> settings for multiple instances of this program.  It will be run on
[quoted text clipped - 8 lines]
>
> So, is there a class in c# to read in .ini files?

The method i suggested results in a text file, which could be
modified.  Although I think that's a bad idea.  What if the user puts
something unexpected in there?

And its not the best way to share settings.. if you really want to
share settings, typically this is done in some sort of database.  Then
it would be change once and done.
titan nyquist - 30 May 2007 20:42 GMT
> if you really want to
> share settings, typically this is done in some sort of database.  Then
> it would be change once and done.

I agree.  I will think about how to do this more.

~titan
Moty Michaely - 30 May 2007 14:52 GMT
> > What kind of settings do you need to store?
>
[quoted text clipped - 10 lines]
>
> Titan

Hi,

Andy suggested the best solution for you.

The settings resource auto generates resources class that you can use
to subscribe for "SettingChanging" etc. events.
The auto generator creates an auto generated class that inherits
ApplicationSettingsBase.

Hope this helps.
Moty
titan nyquist - 30 May 2007 14:56 GMT
> Andy suggested the best solution for you.
>
> The settings resource auto generates resources class that you can use
> to subscribe for "SettingChanging" etc. events.
> The auto generator creates an auto generated class that inherits
> ApplicationSettingsBase.

I think that is the best solution, typcially.  But now I just
discovered I need the settings store in a text file, that can be
modified by the user.  I figured .ini files are the best option, and
if c# supports them with any classes it would be great.

~titan
Moty Michaely - 30 May 2007 15:08 GMT
> > Andy suggested the best solution for you.
>
[quoted text clipped - 9 lines]
>
> ~titan

Hi,

XML files in general are textual files, and they are pretty
readable...

Moty

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.