All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,MVC+LINQ开发一个图书销售站点(3)-建立数据库_[Asp.Net教程]
SQL中的五种数据类型_[SQL,Server教程]
DotNet中用到的加密算法总结_[Asp.Net教程]
动态SQL四种类型的语句格式_mssql学习_编程技术
HTML语言剖析(一)Html简介_[Html教程]
Asp.Net文件处理_[Asp.Net教程]
.Net+MySQL组合开发(二),数据访问篇_[Asp.Net教程]
C#中CheckBox控件应用实例
SQL,Server,2000安装故障_[SQL,Server教程]
C#动态生成树型结构的Web程序设计实例_.net资料_编程技术
Reading number is top 10 pictures
Magnificent cloud2
这年头,找个靠谱的妹子太难了
Gang rape
到南昌西站了3
星星命名法则
Female model behind the bitterness, often being overcharged5
Ashlynn Brooke show proud chest measurement3
擦地板的大叔太好了
赵惟依写真2
The real super beauty15
Download software ranking
Ashlynn Video2
Ashlynn Video4
Boxer Classic video2
天龙八部最新服务端
Ashlynn Video5
DreamWeaver8
Unix video tutorial2
Tram sex maniac 2 (H) rar bag13
Proficient in JavaScript
apache-tomcat-6.0.33
delv published in(发表于) 2014/1/6 8:46:42 Edit(编辑)
.Net2.0,使用ConfigurationManager读写配置文件_[Asp.Net教程]

.Net2.0,使用ConfigurationManager读写配置文件_[Asp.Net教程]

.Net2.0 使用ConfigurationManager读写配置文件_[Asp.Net教程]

.net1.1中如果需要灵活的操作和读写配置文件并不是十分方便,一般都会在项目中封装一个配置文件管理类来进行读写操作。而在.net2.0中使用ConfigurationManager 和WebConfigurationManager 类可以很好的管理配置文件,ConfigurationManager类在System.Configuration中,WebConfigurationManager在System.Web.Configuration中。根据MSDN的解释,对于 Web 应用程序配置,建议使用 System.Web.Configuration.WebConfigurationManager 类,而不要使用 System.Configuration.ConfigurationManager 类。

  下面我给出一个简单的例子说明如何使用WebConfigurationManager操作配置文件:


//打开配置文件
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
//获取appSettings节点
AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");
//在appSettings节点中添加元素
appSection.Settings.Add("addkey1", "key1's value");
appSection.Settings.Add("addkey2", "key2's value");
config.Save();


  运行代码之后可以看见配置文件中的改变:






  修改和删除节点或属性也非常方便:


//打开配置文件
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
//获取appSettings节点
AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");
//删除appSettings节点中的元素
appSection.Settings.Remove("addkey1");
//修改appSettings节点中的元素
appSection.Settings["addkey2"].Value = "Modify key2's value";
config.Save();


  配置文件:





来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.