Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » How To » Downloads
 
Add your own
alternative version

Reading and Writing Configuration Application Block: Enterprise Library 1.0

, 27 Apr 2005
Reading and writing Configuration Application Block.
configuration__src.zip
Configuration Application Block
bin
Configuration Application Block.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Configuration Application Block.csproj.webinfo
Global.asax
_vti_cnf
_vti_pvt
access.cnf
deptodoc.btr
doctodep.btr
service.cnf
service.lck
services.cnf
_vti_script
_vti_txt
/*
  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)

Share

About the Author

santosh poojari
Technical Lead
India India
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

| Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 28 Apr 2005
Article Copyright 2005 by santosh poojari
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid