views:

139

answers:

3

How do you use the COnfigurationManager class to read and write to the settings file?

A: 

check the following
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
http://www.codeproject.com/KB/cs/SystemConfiguration.aspx

Space Cracker
One thing I have been experiencing is that a rogue string comes up when I do a loop through the connectionstrings section I have no idea, how this rogue string is being populated. For example, my connectionStrings section has gota> prodb> devc> uatstrings in it.When I loop through connectionStrings section, using this code. foreach (ConnectionStringSettings key in ConfigurationManager.ConnectionStrings) { Console.WriteLine("ConKey: {0}, Value:{1}", key.Name, key.ConnectionString.ToString()); } I get 4 strings.
abhi
A: 

One thing that might catch you out is that to access the ConfigurationManager class you have to manually add a reference to System.Configuration. The System.Configuration namespace is split across multiple assemblies - you only get part of it by default.

Space Cracker posted some good links, but there is also a way to write strongly typed configuration sections, which I blogged about a few years ago - Configuring a .NET 2.0 Application Using the ConfigurationSection class. I've literally never seen anyone else use strongly typed ConfigurationSections, but once you get used to them they're quite useful.

Alex Humphrey
A: 

I could try and give you the breakdown here but really the following links, all written by Jon Rista, are the best resources I have found regarding the System.Configuration namespace.

Unravelling the Mysteries of .NET 2.0 Configuration

Decoding the Mysteries of .NET 2.0 Configuration

Cracking the Mysteries of .NET 2.0 Configuration

Bronumski
Thanks for the links.
abhi
Thanks for the links. The final link contained a reference to the machine.config file. This file contains my "rogue" string mentioned in my comment to SpaceCracker below. I believe I have figured out the configuration management system for .NEt executables.
abhi