企业库Configuration Application Block 使用
新建 工程, 用Enterprise Library Configuration打开 web.config
新建 configsection .
重命名为 Edit ,
然后在edit 结点新建
XML File Storage Provider
Xml Serializer Transformer
设置 XML File Storage Provider 它的filename 为存取信息的 config文件
(你要先在项目中新建一个config 文件,在试例中命名为 Setting.config)
然后保存
![](/images/cnblogs_com/gwazy/EntLib.jpg)
using System;
using System.Text;
using System.Xml.Serialization;
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
namespace Intlib
{
/// <summary>
/// Persen 的摘要说明。
/// </summary>
public class Persen
{
private string name ;
private int age;
private string country;
![](/Images/OutliningIndicators/InBlock.gif)
public Persen()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
![](/Images/OutliningIndicators/InBlock.gif)
public string Name
{
get{ return name; }
set{ name = value; }
}
![](/Images/OutliningIndicators/InBlock.gif)
public int Age
{
get{return age ;}
set{age=value ;}
}
public string Country
{
get{return country ;}
set{country=value ;}
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/InBlock.gif)
}
}
一个为写入,一个为读取,
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
private void Button1_Click(object sender, System.EventArgs e)
{
Persen ps=new Persen ();
ps.Name=this.TextBox1 .Text ;
ps.Age =int.Parse (this.TextBox2.Text) ;
ps.Country =this.TextBox3.Text ;
ConfigurationManager.WriteConfiguration ("Edit",ps);
![](/Images/OutliningIndicators/InBlock.gif)
}
![](/Images/OutliningIndicators/None.gif)
private void Button2_Click(object sender, System.EventArgs e)
{
Persen ps = ConfigurationManager.GetConfiguration("Edit") as Persen ;
this.TextBox1 .Text =ps.Name;
this.TextBox2.Text =ps.Age.ToString ();
this.TextBox3.Text =ps.Country ;
![](/Images/OutliningIndicators/InBlock.gif)
}
企业库会对对象自动进行序列化,和反序列化...
方便从 config中读取和写入.....
新建 configsection .
重命名为 Edit ,
然后在edit 结点新建
XML File Storage Provider
Xml Serializer Transformer
设置 XML File Storage Provider 它的filename 为存取信息的 config文件
(你要先在项目中新建一个config 文件,在试例中命名为 Setting.config)
然后保存
![](/images/cnblogs_com/gwazy/EntLib.jpg)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
一个为写入,一个为读取,
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
企业库会对对象自动进行序列化,和反序列化...
方便从 config中读取和写入.....