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

T

titan nyquist

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
 
A

Andy

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
 
T

titan nyquist

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)?
 
M

Moty Michaely

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

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

Moty
 
T

titan nyquist

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
 
T

titan nyquist

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
 
M

Moty Michaely

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

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
 
M

Mark Rae

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?

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
 
T

titan nyquist

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
 
M

Moty Michaely

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

Hi,

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

Moty
 
A

Andy

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?

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.
 
T

titan nyquist

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top