Click here to Skip to main content
13,831,763 members
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 27 Apr 2005
Licenced CPOL

Reading and Writing Configuration Application Block: Enterprise Library 1.0

, 27 Apr 2005
Rate this:
Please Sign up or sign in to vote.
Reading and writing Configuration Application Block.


The Enterprise Library is altogether a new concept in the .NET Framework. I found very few resource on this in the Internet. Here I show how to implement the reading and writing of configuration files of the Enterprise Library coupled with your web application. On exploring the strength of the application, I thought of presenting the new concepts of the Enterprise Library for application development. So here I am presenting one of the blocks of Enterprise Library. Before going to this sample, please go through the actual concepts written by Microsoft MSDN.

Key Scenario:

For running your application, you require to install Enterprise Library 1.0. One can download Enterprise Library 1.0 here.


  • Microsoft.Practices.EnterpriseLibrary.Configuration.dll

Step By Step Implementation

Here we go with actual Configuration Application block where one can learn to read and write the configuration files.

  1. Create one ASP.NET Web Application project named Configuration Application Block, from Microsoft Visual Studio..
  2. Under this project, create one web form named RXConfiguration.aspx.
  3. This is an important step. If Enterprise Library is installed in your system, go to Program menu, click on ‘Microsoft Patterns and Practices’, there you will find ‘Enterprise Library’, under it, open ‘Enterprise Library Configuration’.
  4. Once Enterprise Library Configuration is open, click on File menu, select Open Application. Now you will see the file browser window. Browse your application under inetpub/wwwroot/Configuration Application Block and select Web.config file and click OK.
  5. See the image below. You will find that under Enterprise Library Configuration, there appears an Application menu. Now right click on Application, select New, and under it select Configuration Application Block.

    Sample Image

  6. You will find Configuration Application Block appears below the node Application. Next step is to right click on Configuration Application Block and select Configuration Section.

    Important note: Change the name of Configuration Section to FormatSection.

    Sample Image

  7. Right click on Configuration Section (FormatSection), select New, under which appears XML File Storage Provider. On the right side, one can find the General section of XML File Storage Provider. Give some filename as formatsetting.config.

    Sample Image

  8. Again, right click on Configuration Section, select New, under which appears XML Serializer Transformer.
  9. Now save the file.
  10. On doing so, go to your ASP.NET web application. In Solution Explorer, click on Show All Files icon. You will find that formatseting.config file appears on project files.
  11. Add References. Click on Browse, path Program Files/Microsoft Enterprise Library/bin. Add References of Microsoft.Practices.EnterpriseLibrary.Configuration.dll.

    Sample Image

  12. Now do the code behind coding in RXConfiguration.aspx.cs.

See the user interface of this example:

Sample Image

Include the namespace: using Microsoft.Practices.EnterpriseLibrary.Configuration.

Before this, create one class file named ClsFormatSetting.cs where one can specify the properties and methods required for reading and writing Confiq files.

public class FormatSettingData
    private string  firstName;
    private string  lastName;
    private string  designation;
    private string  filePath;
    private string  name;
    private float   size;
    private int     style;
    public FormatSettingData()

    public string Name 
        get{ return name; }
        set{ name = value; }
    public string FirstName 
        get{ return firstName; }
        set{ firstName = value; }
    public string LastName 
        get{ return lastName; }
        set{ lastName = value; }
    public string Designation 
        get{ return designation; }
        set{ designation = value; }
    public string FilePath 
        get{ return filePath; }
        set{ filePath= value; }
    public float Size 
        get{ return size; }
        set{ size = value; }

    public int Style 
        get{ return style; }
        set{ style = value; }

    public override string ToString() 
        StringBuilder sb = new StringBuilder();
        sb.AppendFormat("FirstName = {0}; LastName = {1};" + 
                   " Designation = {2}; FilePath={3}", 
                   FirstName.ToString(), LastName.ToString(), 
        return sb.ToString();

The above code specifies person details, file path, format font type. I would have made it more object oriented by defining different classes for them. In order to make things look simpler, I did this.

Now time to write some code in RXConfiguration.aspx.cs.

private FormatSettingData objFormatData=new FormatSettingData();
public void btnWriteXml_Click(object sender, System.EventArgs e)
    // This write into Configuration file created by Enterprise Library Console
    //Write into File named formatsetting.config

    //Data required to be written into Congig file

    objFormatData = new FormatSettingData();
    objFormatData.Name = "Tahoma";
    objFormatData.Size = 14;
    objFormatData.Style = 2;

    // Write the new configuration data to the XML file
    //***Important In Enterprise Library Change Configuration Section into
    ConfigurationManager.WriteConfiguration("FormatSection", objFormatData);

Read configuration data from formatsetting.config file:

//On click of Read button data from Config file get populated into 
//Text Area Box as shown in figure above.
public void btnReadXml_Click(object sender, System.EventArgs e)
    // Read configuration data from formatsetting.config file 
    objFormatData =
      ConfigurationManager.GetConfiguration("FormatSection") as FormatSettingData; 

Now we can format the text in the text area box with the code below. See that we have specified the format of text information in the Config file.

public void btnFormatText_Click(object sender, System.EventArgs e)
    //Do the formatting of text from font settings 
    //defined in formatsetting.config file
    objFormatData =
        as FormatSettingData;

You can see the format of XML written in the formatsetting.config file.

<?xml version="1.0" encoding="utf-8"?>
< FormatSection>
  < xmlSerializerSection type=
     Configuration Application Block, Version=1.0.1937.19238, 
     Culture=neutral, PublicKeyToken=null">
    < FormatSettingData xmlns:xsd="" 

      < Name>Tahoma</Name>
      < FirstName>Santosh < /FirstName>
      < LastName>Poojari < /LastName>
      < Designation>Programmer < /Designation>
      < FilePath></FilePath>
      < Size>14</Size >
      < Style>2</Style >
    < /FormatSettingData >
  < /xmlSerializerSection >
</FormatSection >

That's all...



The basic idea is to give a jumpstart to the newer technologies on the block. Hope I have reached to the expectation of the learner. Criticism, suggestions, any information are most welcomed.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

santosh poojari
Technical Lead
Australia Australia
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!

You may also be interested in...


Comments and Discussions

GeneralUsing the same Enterprise Library 2.0 Or .Net 2.0 Pin
Bijay Bhaskar Deo24-Jun-07 20:34
memberBijay Bhaskar Deo24-Jun-07 20:34 
General.Net 2.0 Pin
Amir Venter19-May-06 5:35
memberAmir Venter19-May-06 5:35 
GeneralRe: .Net 2.0 Pin
Shiv...8-Feb-07 0:28
memberShiv...8-Feb-07 0:28 
GeneralRe: .Net 2.0 Pin
Mark Falto25-Feb-09 12:08
memberMark Falto25-Feb-09 12:08 
GeneralIDM.Net Configuration Pin
VlastaH29-Mar-06 14:19
memberVlastaH29-Mar-06 14:19 
GeneralApplication block data source modification Pin
Delphig27-Feb-06 20:33
memberDelphig27-Feb-06 20:33 
GeneralMore than one Class in the XML File Pin
Ricardo Casquete22-Feb-06 4:05
memberRicardo Casquete22-Feb-06 4:05 
GeneralConfiguration parameters... Pin
T1Pimp23-May-05 8:21
memberT1Pimp23-May-05 8:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190114.1 | Last Updated 28 Apr 2005
Article Copyright 2005 by santosh poojari
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid