Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

C# Programming

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


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

On May 30, 8:49 am, titan nyquist <titan.nyqu@gmail.com> wrote:

> 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

-----------------------------------------------Reply-----------------------------------------------

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

-----------------------------------------------Reply-----------------------------------------------
On May 30, 3:53 pm, Andy <a@med-associates.com> wrote:

> On May 30, 8:49 am, titan nyquist <titan.nyqu@gmail.com> wrote:

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

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

Moty

-----------------------------------------------Reply-----------------------------------------------

> 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

-----------------------------------------------Reply-----------------------------------------------

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

-----------------------------------------------Reply-----------------------------------------------

On May 30, 4:21 pm, titan nyquist <titan.nyqu@gmail.com> wrote:

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

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

-----------------------------------------------Reply-----------------------------------------------

> 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

-----------------------------------------------Reply-----------------------------------------------

"titan nyquist" <titan.nyqu@gmail.com> wrote in message

news:1180532236.160174.13910@p77g2000hsh.googlegroups.com...

>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....
http://www.pinvoke.net/default.aspx/kernel32/WritePrivateProfileStrin...

--
http://www.markrae.net

-----------------------------------------------Reply-----------------------------------------------

On May 30, 4:56 pm, titan nyquist <titan.nyqu@gmail.com> wrote:

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

Hi,

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

Moty

-----------------------------------------------Reply-----------------------------------------------

On May 30, 9:37 am, titan nyquist <titan.nyqu@gmail.com> wrote:

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

-----------------------------------------------Reply-----------------------------------------------

> 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

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc