C#自定义ConfigSections节 操作 。
sectiongroup:
在config文件中加入以下节点:
- <configSections>
- <sectionGroup name="WebSiteInfo">
- <section name="basicInfo" type="ConfigurationSectionTest.WebSiteInfoHandler"/>
- <section name="fileUpload" type="ConfigurationSectionTest.WebSiteInfoHandler"/>
- </sectionGroup>
- </configSections>
- <WebSiteInfo>
- <basicInfo>
- <add key="name" value="huchen's homepage"/>
- <add key="version" value="1.0"/>
- </basicInfo>
- <fileUpload>
- <add key="fileUploadPath" value="E:\\MyHomePage\\Web\\Upload\\"/>
- <add key="fileUploadSizeMax" value="2M"/>
- </fileUpload>
- </WebSiteInfo>
![](http://static.blog.csdn.net/images/save_snippets.png)
<configSections><sectionGroup name="WebSiteInfo"><section name="basicInfo" type="ConfigurationSectionTest.WebSiteInfoHandler"/><section name="fileUpload" type="ConfigurationSectionTest.WebSiteInfoHandler"/></sectionGroup>
</configSections><WebSiteInfo><basicInfo><add key="name" value="huchen's homepage"/><add key="version" value="1.0"/></basicInfo><fileUpload><add key="fileUploadPath" value="E:\\MyHomePage\\Web\\Upload\\"/><add key="fileUploadSizeMax" value="2M"/></fileUpload>
</WebSiteInfo>
获取其中的值
- string sectionGroup = "WebSiteInfo";
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- foreach (ConfigurationSection cfgSection in config.GetSectionGroup(sectionGroup).Sections)
- {
- string strSectionName = cfgSection.SectionInformation.Name;
- Hashtable ht = ConfigurationManager.GetSection(sectionGroup + "/" + strSectionName) as Hashtable;
- if (strSectionName=="basicInfo")
- {
- string strSite = ht["name"].ToString();
- string strWeb = ht["version"].ToString();
- }
- }
![](http://static.blog.csdn.net/images/save_snippets.png)
string sectionGroup = "WebSiteInfo";Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);foreach (ConfigurationSection cfgSection in config.GetSectionGroup(sectionGroup).Sections){string strSectionName = cfgSection.SectionInformation.Name;Hashtable ht = ConfigurationManager.GetSection(sectionGroup + "/" + strSectionName) as Hashtable;if (strSectionName=="basicInfo"){string strSite = ht["name"].ToString();string strWeb = ht["version"].ToString();}}
section:
在config文件中加入以下节点:
- <configuration>
- <configSections>
- <section name="sampleSection"
- type="System.Configuration.SingleTagSectionHandler" />
- </configSections>
- <sampleSection setting1="Value1"
- setting2="value two"
- setting3="third value" />
- </configuration>
![](http://static.blog.csdn.net/images/save_snippets.png)
<configuration><configSections><section name="sampleSection"type="System.Configuration.SingleTagSectionHandler" /></configSections><sampleSection setting1="Value1" setting2="value two" setting3="third value" /></configuration>
获取其中的值
- Hashtable ht = ConfigurationManager.GetSection("sampleSection") as Hashtable;
- string str1=ht["setting1"];
![](http://static.blog.csdn.net/images/save_snippets.png)
Hashtable ht = ConfigurationManager.GetSection("sampleSection") as Hashtable;string str1=ht["setting1"];
http://technet.microsoft.com/zh-cn/magazine/ms228245(VS.90).aspx
http://www.cnblogs.com/jhxk/articles/1609182.html
http://apps.hi.baidu.com/share/detail/22169344
C#自定义ConfigSections节 操作 。相关推荐
- C#自定义ConfigSections节点操作
sectiongroup: 在config文件中加入以下节点: [html] view plaincopy print? <configSections> <sectionGroup ...
- 自定义配置节 Section
项目中遇到需求:随时通过增删改配置文件中配置节,来修改程序获取的配置,这里应用到自定义配置节section type="System.Configuration.NameValueSect ...
- C# App.config 自定义 配置节
方法一. App.config <?xml version="1.0" encoding="utf-8" ?> <configuration& ...
- 自定义配置节与配置节的读取
一.引子 你是否也遇到过这样的问题:项目很多配置都写到了App.Config或Web.Config的AppSettings内,每个人都加了几条,到最后囤积了大量的配置,分不清哪个是有用的.哪个是没用的 ...
- 如何在.config文件自定义配置节
在.NET程序中一般都有个应用程序配置文件在ASP.NET中是web.config,在控制台应用程序和Windows应用程序中是app.config.我们通常使用此配置文件来设置一些程序会用到的信息, ...
- 萌新向Python数据分析及数据挖掘 第一章 Python基础 第三节 列表简介 第四节 操作列表...
第一章 Python基础 第三节 列表简介 列表是是处理一组有序项目的数据结构,即可以在一个列表中存储一个序列的项目.列表中的元素包括在方括号([])中,每个元素之间用逗号分割.列表是可变的数据类型, ...
- JPOM - AOP+自定义注解实现操作日志记录
文章目录 地址 版本 源码解析-AOP+自定义注解实现操作日志记录 地址 Gitee: https://gitee.com/dromara/Jpom 官网: https://jpom.io/ 一款简而 ...
- web.config文件之自定义错误节
web.config文件之自定义错误节 大家都知道,在开发asp.net应用程序时,通过web.config文件可以配置在执行 Web 请求期间发生未处理的错误时,ASP.NET 显示信息的方式.下面 ...
- VBS操作IE ---(【当不使用IE时】可以使用Chrome插件,自定义JS插件操作浏览器)
目录 ■前言 ■举个简单VBS操作IE的例子 --- ■如何让IE打开是IE,而不是Edge ■其他更多VBS相关 ・更多操作一览 ・按键 shift ctrl alt ・打开图片,以幻灯片形式显示 ...
最新文章
- c#数据结构———二叉查找树
- python:ElementTree操作XML
- Laravel 5.1 artisan 的使用
- PID算法搞不懂?看这篇文章就够了。
- (2021年)IT技术分享社区个人文章汇总(电脑技巧篇)
- 前端学习(3329):闭包的形式5
- echo输出换行_Bash shell教程[5] echo命令
- 使用 show status 命令
- 云原生游戏《云联物语》揭开神秘面纱 云鹭科技温向东带你深度了解云原生游戏领域...
- 微信小程序input详解
- 当安装完Windows系统后出现“系统保留”分区该怎么办?
- 武装突袭3多人服务器文件地图,武装突袭3地图文件夹 | 手游网游页游攻略大全...
- Use junit to test Trangle problem
- Program week9 work
- 垃圾收集 (Garbage Collection,GC)
- 100!的尾数有多少个零?
- RAID的基本工作模式
- 小学学校计算机里的单机游戏,15年前的农村小网吧,那个时候只能玩这些单机游戏...
- SDNFV Fest论坛成功举办 全景展现SDN/NFV测试成果
- AtCoder Beginner Contest 254 A~E 题解
热门文章
- spark java8 scala_在 Ubuntu16.04 中搭建 Spark 单机开发环境 (JDK + Scala + Spark)
- 工具类的方法怎么引用_Java实用工具类:File工具类方法学习,可创建目录及文件...
- 配置中文_《洛克人Zero/ZX遗产合集》PC配置公布 支持中文
- 没有域可以加文件服务器吗,文件服务器没有域
- 海上瓶子下有东西吗_小小的瓶盖竟有如此大的作用, 闻名不如眼见, 你知道吗?...
- cocos2dx ios入口类_2.cocos2d-x 第一个项目
- 19年三本毕业,做了三年的嵌入式软件。
- PCB上晶振布局是个技术活,避开PCB的边缘很重要
- auto与迭代器的用法_C++ STL move_iterator移动迭代器用法详解
- python或运算 和 in_Python’的奇怪行为是’运算符,如果与’in’结合使用[复制]