Alois Kraus


  Home  |   Contact  |   Syndication    |   Login
  133 Posts | 8 Stories | 368 Comments | 162 Trackbacks



Post Categories


This time I would like to show you the most important changes in the System.Configuration namespace with .NET 2.0.
I have looked at my blog referrer statistics and saw about 20 hits/day by google. Most of them were searching 
infos how to configure the new Enterprise Library but also a significant number of people which seem to seek guidance to the
following questions:
  • How to read/write to App.Config?
  • How to store a list of objects in a config file via the System.Configuration mechanism?
Reason enough for me to shed more light on the System.Configuration namespace.
The main changes from .NET 1.0/1.1 in the System.Configuration namespace are:
  • Write to your App.Config file through the Configuration class.
  • New configuration model for Windows Forms applications.
  • Store complex objects including object collections in your App.Config File.
  • It is possible to store Connection Strings in the App.Config file see ConnectionSettings this enables you to store you settings on a SQL Server. The Enterprise Library for Sample SqlConfiguration exercises this by implementing a SqlConfigurationSource which can store and retrieve a ConfigurationSection.
So where to start? I think I show you at first the config file and explain how you can create it programtically in your application.

The easiest way to read/write AppSettings

If you want to store only key/value pairs in your App.config file there is a special section in reserved which allows you to do exactly that. Simply add an <appsettings> section and add your data as key/value pairs of the form <add key="xxx" value="xxxx" />. Thats all to create new app.config file with settings in it.


<?xml version="1.0" encoding="utf-8" ?>



    <add key="Setting1" value="Very" />

    <add key="Setting2" value="Easy" />



Show more ....
posted on Wednesday, January 4, 2006 11:00 PM


# re: Read/Write App.config with .NET 2.0/Enterprise Library 7/24/2006 3:29 AM thachvv
How can i config in another table for Endlib. ex: users for asp_users

# re: Read/Write App.config with .NET 2.0/Enterprise Library 8/26/2006 11:09 AM Lars
You must add the system.configuration to the reference of the project. He should have mentioned this.

# re: Read/Write App.config with .NET 2.0/Enterprise Library 9/21/2007 3:44 AM Mayra
My problem is: I have several projects within my solution. Each project have an AppConfig file, I need integrate the configuration values of all AppConfig files in an main AppConfig, How can I integrate all configuration values in the AppConfig file from a project that is the start up project? Thanks.

Post A Comment