您的位置:首页 > 移动开发

APP.config/web.config编辑类

2005-08-05 11:04 239 查看
using System;
using System.Configuration;
using System.Reflection;
using System.Web;
using System.Xml;

public enum ConfigFileType

namespace fenghua.Configuration

使用方法:

1.app.config

private void Form1_Load(object sender, System.EventArgs e)
{
AppConfig config = new AppConfig();
config.ConfigType= (int)ConfigFileType.AppConfig;

bool   bln=  (bool)( config.GetValue( "Boolean", typeof( bool ) ) );
string  str= (string)( config.GetValue( "String", typeof( string ) ) );
DateTime date = (DateTime)( config.GetValue( "DateTime", typeof( DateTime ) ) );

bln  = !bln;
str  = str + "-" + "there";
date = date.AddDays( 1 );

config.SetValue( "Boolean", bln.ToString() );
config.SetValue( "String", str );
config.SetValue( "DateTime", date.ToShortDateString() );
config.SetValue("testing", "1234506");

config.SetValue("howdy", "there");
string  str2= (string)( config.GetValue( "howdy", typeof( string ) ) );

textBox1.Text+= bln +"         ";
textBox1.Text+= str2+"      " ;
textBox1.Text+= date.ToShortDateString()+"       " ;
// uncomment to see element removed
//config.removeElement("howdy");

}

2.修改web.config:

private void Page_Load(object sender, System.EventArgs e)
{

AppConfig config = new AppConfig();
//config.ConfigType = (int)ConfigFileType.WebConfig;

bool   bln=  (bool)( config.GetValue( "Boolean", typeof( bool ) ) );
string  str= (string)( config.GetValue( "String", typeof( string ) ) );
DateTime date = (DateTime)( config.GetValue( "DateTime", typeof( DateTime ) ) );

bln  = !bln;
str  = str + "-" + "there";
date = date.AddDays( 1 );

config.SetValue( "Boolean", bln.ToString() );
config.SetValue( "String", str );
config.SetValue( "DateTime", date.ToShortDateString() );
config.SetValue("testing", "1234506");
config.SetValue("howdy", "there");
string  str2= (string)( config.GetValue( "howdy", typeof( string ) ) );

Response.Write( bln + "<BR>" );
Response.Write( str2  + "<BR>");
Response.Write( date.ToShortDateString() + "<BR>" );
// uncomment to see element removed
//config.removeElement("howdy");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: