.Net2.0使用ConfigurationManager读写配置文件
来源:互联网 发布:let it go原唱 编辑:程序博客网 时间:2024/06/02 05:31
下面我给出一个简单的例子说明如何使用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();
运行代码之后可以看见配置文件中的改变:
<appSettings>
<add key="addkey1" value="key1's value" />
<add key="addkey2" value="key2's value" />
</appSettings>
修改和删除节点或属性也非常方便:
//打开配置文件
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();
配置文件:
<appSettings>
<add key="addkey2" value="Modify key2's value" />
</appSettings>
参考:http://msdn2.microsoft.com/en-us/library/ms228060.aspx
http://justicfu.cnblogs.com/archive/2006/06/21/431632.html
- .net2.0 使用configurationmanager读写配置文件
- .Net2.0 使用ConfigurationManager读写配置文件
- .Net2.0 使用ConfigurationManager读写配置文件
- .Net2.0 使用ConfigurationManager读写配置文件
- .Net2.0 使用ConfigurationManager读写配置文件
- .Net2.0 使用ConfigurationManager读写配置文件
- .Net2.0使用ConfigurationManager读写配置文件
- .Net2.0使用ConfigurationManager读写配置文件
- 使用ConfigurationManager类 读写配置文件
- 使用ConfigurationManager类 读写配置文件
- ASP.NET 使用ConfigurationManager读写配置文件
- asp.net2.0 中ConfigurationManager使用的问题
- 抛弃ConfigurationManager , 实现面向对象读写配置文件
- C#使用ConfigurationManager类操作配置文件
- 在WPF中使用配置文件(ConfigurationManager)
- ASP.NET2.0怎么读写web.config配置文件
- NET2.0的配置文件
- NET2.0的配置文件
- ASP.NET2.0下的条件编译
- ASP.NET2.0中XSLT的使用
- ASP.NET2.0中的母版页详解
- ASP.Net2.0GridView多列排序,显示排序图标,分页
- ASP.NET中实现模板页
- .Net2.0使用ConfigurationManager读写配置文件
- .net做的IP访问限制
- ASP.NET2.0数据库入门之常见错误
- 在VS2003中直接用DREAMWEAVER8打开ASPX文件
- asp.net2.0中异步调用WebService(异步页)
- 使用DataAccessApplicationBlock得到存储过程的返回值
- 请求网址并解析返回的html
- 一段比较经典的多线程学习代码
- 一些常用的数据操作类