Introduction
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.
Dependencies
- 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.
- Create one ASP.NET Web Application project named Configuration Application Block, from Microsoft Visual Studio..
- Under this project, create one web form named RXConfiguration.aspx.
- 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�.
- 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.
- 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.

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

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

- Again, right click on Configuration Section, select New, under which appears XML Serializer Transformer.
- Now save the file.
- 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.
- Add References. Click on Browse, path Program Files/Microsoft Enterprise Library/bin. Add References of Microsoft.Practices.EnterpriseLibrary.Configuration.dll.

- Now do the code behind coding in RXConfiguration.aspx.cs.
See the user interface of this example:

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(),
Designation.ToString(),FilePath.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)
{
btnReadXml.Enabled=true;
btnFormatText.Enabled=true;
objFormatData = new FormatSettingData();
objFormatData.FirstName="Santosh";
objFormatData.LastName="Poojari";
objFormatData.Designation="Programmer";
objFormatData.FilePath="http://www.codeprojects.com";
objFormatData.Name = "Tahoma";
objFormatData.Size = 14;
objFormatData.Style = 2;
ConfigurationManager.WriteConfiguration("FormatSection", objFormatData);
btnWriteXml.Enabled=false;
}
Read configuration data from formatsetting.config file:
public void btnReadXml_Click(object sender, System.EventArgs e)
{
objFormatData =
ConfigurationManager.GetConfiguration("FormatSection") as FormatSettingData;
txtReader.Text=objFormatData.ToString();
}
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)
{
objFormatData =
ConfigurationManager.GetConfiguration("FormatSection")
as FormatSettingData;
txtReader.Font.Name=objFormatData.Name;
txtReader.Font.Size=(FontUnit)objFormatData.Size;
}
You can see the format of XML written in the formatsetting.config file.
="1.0" ="utf-8"
< FormatSection>
< xmlSerializerSection type=
"Configuration_Application_Block.FormatSettingData,
Configuration Application Block, Version=1.0.1937.19238,
Culture=neutral, PublicKeyToken=null">
< FormatSettingData xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
< Name>Tahoma</Name>
< FirstName>Santosh < /FirstName>
< LastName>Poojari < /LastName>
< Designation>Programmer < /Designation>
< FilePath>http://www.codeprojects.com</FilePath>
< Size>14</Size >
< Style>2</Style >
< /FormatSettingData >
< /xmlSerializerSection >
</FormatSection >
That's all...
References
Conclusion
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.