Connecting Tech Pros Worldwide Forums | Help | Site Map

Cracking ConfigurationManager

Jonathan Wood
Guest
 
Posts: n/a
#1: Aug 3 '07
This is crazy. Does anyone have a simple example of reading a variable from
the application config file for a desktop application?

I've spent way too much time on this. I've found huge examples and lots of
help topics. But the .NET help topics are beyond poor. And that makes it
difficult for me to completely understand huge examples. And the smaller
examples I've managed to find don't work.

Since I want to get my application to do a few things in addition to reading
and writing the settings, I'd prefer to find a simple example and be able to
move on.

Has anyone out there cracked ConfigurationManager for a desktop app?

Thanks.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com




G.Doten
Guest
 
Posts: n/a
#2: Aug 3 '07

re: Cracking ConfigurationManager


Smithers wrote:
Quote:
2. If you want to programmatically write (in addition to reading), then you
have to go the more complex route presented in the links I gave earlier and
discussed below.
If you use Visual Studio 2005 you can just right-click on a project's
Properties node and select Open. Then go to the Settings tab. Just type
in you new setting's name and a default value. If you make the setting
application-copied then it cannot be written to; if you make the setting
user-scoped it can be written to easily.

VS will generate a Settings.cs file with a Settings class in it. To use
this just do this:

using <your-namespace>.Properties;

int maxLoops = Settings.Default.MaxLoops;

// You can now use maxLoops as you would like.

Settings.Default.MaxLoops = 154;
Settings.Default.Save();

// You've just changed the MaxLoops setting to be 154.

This doesn't read and/or write to the <appSettingssection but is great
for adding user- or application-specific settings right in your class
library and/or application. But these VS-supported settings are wicked
simple to use and very flexible (say you're working on a class library,
the settings for that library can easily be copied to an app.config for
tailoring by code that uses the class library).

I decided to go through the pain of converting all my .NET 1.1 and prior
based ConfigurationSettings stuff to this new technique because the new
stuff didn't seem to be worth figuring out giving the VS built-in
support for the new settings. If MS does a wholesale change of the
"settings architecture" again I'm sticking with this one introduced in
..NET 2.0 - [obsolete] or not!

--
-glenn-
Smithers
Guest
 
Posts: n/a
#3: Aug 3 '07

re: Cracking ConfigurationManager


Thanks for pointing out something I had missed.

The Settings.cs and related VS functionality of which you speak: is it
limited to name/value pairs - or can we also store collections of related
stuff?

-"Smithers"






"G.Doten" <gdoten@gmail.comwrote in message
news:u%23aqvre1HHA.5644@TK2MSFTNGP05.phx.gbl...
Quote:
Smithers wrote:
Quote:
>2. If you want to programmatically write (in addition to reading), then
>you have to go the more complex route presented in the links I gave
>earlier and discussed below.
>
If you use Visual Studio 2005 you can just right-click on a project's
Properties node and select Open. Then go to the Settings tab. Just type in
you new setting's name and a default value. If you make the setting
application-copied then it cannot be written to; if you make the setting
user-scoped it can be written to easily.
>
VS will generate a Settings.cs file with a Settings class in it. To use
this just do this:
>
using <your-namespace>.Properties;
>
int maxLoops = Settings.Default.MaxLoops;
>
// You can now use maxLoops as you would like.
>
Settings.Default.MaxLoops = 154;
Settings.Default.Save();
>
// You've just changed the MaxLoops setting to be 154.
>
This doesn't read and/or write to the <appSettingssection but is great
for adding user- or application-specific settings right in your class
library and/or application. But these VS-supported settings are wicked
simple to use and very flexible (say you're working on a class library,
the settings for that library can easily be copied to an app.config for
tailoring by code that uses the class library).
>
I decided to go through the pain of converting all my .NET 1.1 and prior
based ConfigurationSettings stuff to this new technique because the new
stuff didn't seem to be worth figuring out giving the VS built-in support
for the new settings. If MS does a wholesale change of the "settings
architecture" again I'm sticking with this one introduced in .NET 2.0 -
[obsolete] or not!
>
--
-glenn-

G.Doten
Guest
 
Posts: n/a
#4: Aug 3 '07

re: Cracking ConfigurationManager


Smithers wrote:
Quote:
The Settings.cs and related VS functionality of which you speak: is it
limited to name/value pairs - or can we also store collections of related
stuff?
You can store almost any type you want. Look in Visual Studios' Settings
tab and you'll see a type drop-down for the setting. Set it to whatever
you want. You can even browse to one of your own types.

--
-glenn-
Closed Thread