Click here to Skip to main content
15,885,739 members
Articles / Programming Languages / XML

Reading and Writing Configuration Application Block: Enterprise Library 1.0

Rate me:
Please Sign up or sign in to vote.
3.75/5 (9 votes)
27 Apr 2005CPOL3 min read 78.4K   649   32  
Reading and writing Configuration Application Block.
/*
  Created By Santosh Poojari
  Date Of Creation: 22/04/05
  Reference Enterprise Library of MSDN
  Description:Shows Configuration Application Block Implementation
  Contact:Santosh_poojari@rediffmail.com
    
*/

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using Microsoft.Practices.EnterpriseLibrary.Configuration;
namespace Configuration_Application_Block
{
	/// <summary>
	/// Summary description for Writing_Configuration_Block.
	/// </summary>
	public class Writing_Configuration_Block : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnWriteXml;
		protected System.Web.UI.WebControls.Button btnReadXml;
		protected System.Web.UI.WebControls.Button btnFormatText;
		protected System.Web.UI.WebControls.TextBox txtReader;
		protected System.Web.UI.WebControls.Label Label1;
		private FormatSettingData objFormatData=new FormatSettingData();
		
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(!Page.IsPostBack)
			{
				txtReader.Enabled=false;
				btnReadXml.Enabled=false;
				btnFormatText.Enabled=false;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnWriteXml.Click += new System.EventHandler(this.btnWriteXml_Click);
			this.btnReadXml.Click += new System.EventHandler(this.btnReadXml_Click);
			this.btnFormatText.Click += new System.EventHandler(this.btnFormatText_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

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

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

		public void btnReadXml_Click(object sender, System.EventArgs e)
		{
			// Read configuration data from formatsetting.config file
				objFormatData = ConfigurationManager.GetConfiguration("FormatSection") as FormatSettingData;
				txtReader.Text=objFormatData.ToString();
		}

		public void btnFormatText_Click(object sender, System.EventArgs e)
		{
			//Do the formatting of text from font settings defined in formatsetting.config file
			
			objFormatData = ConfigurationManager.GetConfiguration("FormatSection") as FormatSettingData;
			txtReader.Font.Name=objFormatData.Name;
			txtReader.Font.Size=(FontUnit)objFormatData.Size;
			
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Technical Lead
Australia Australia
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

Comments and Discussions