sectiongroup:

在config文件中加入以下节点:

[html] view plaincopy print?
  1. <configSections>
  2. <sectionGroup name="WebSiteInfo">
  3. <section name="basicInfo" type="ConfigurationSectionTest.WebSiteInfoHandler"/>
  4. <section name="fileUpload" type="ConfigurationSectionTest.WebSiteInfoHandler"/>
  5. </sectionGroup>
  6. </configSections>
  7. <WebSiteInfo>
  8. <basicInfo>
  9. <add key="name" value="huchen's homepage"/>
  10. <add key="version" value="1.0"/>
  11. </basicInfo>
  12. <fileUpload>
  13. <add key="fileUploadPath" value="E:\\MyHomePage\\Web\\Upload\\"/>
  14. <add key="fileUploadSizeMax" value="2M"/>
  15. </fileUpload>
  16. </WebSiteInfo>

<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>

获取其中的值

[csharp] view plaincopy print?
  1. string sectionGroup = "WebSiteInfo";
  2. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  3. foreach (ConfigurationSection cfgSection in config.GetSectionGroup(sectionGroup).Sections)
  4. {
  5. string strSectionName = cfgSection.SectionInformation.Name;
  6. Hashtable ht = ConfigurationManager.GetSection(sectionGroup + "/" + strSectionName) as Hashtable;
  7. if (strSectionName=="basicInfo")
  8. {
  9. string strSite = ht["name"].ToString();
  10. string strWeb = ht["version"].ToString();
  11. }
  12. }

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文件中加入以下节点:

[html] view plaincopy print?
  1. <configuration>
  2. <configSections>
  3. <section name="sampleSection"
  4. type="System.Configuration.SingleTagSectionHandler" />
  5. </configSections>
  6. <sampleSection setting1="Value1"
  7. setting2="value two"
  8. setting3="third value" />
  9. </configuration>

<configuration><configSections><section name="sampleSection"type="System.Configuration.SingleTagSectionHandler" /></configSections><sampleSection setting1="Value1" setting2="value two" setting3="third value" /></configuration>

获取其中的值

[csharp] view plaincopy print?
  1. Hashtable ht = ConfigurationManager.GetSection("sampleSection") as Hashtable;
  2. string str1=ht["setting1"];

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节 操作 。相关推荐

  1. C#自定义ConfigSections节点操作

    sectiongroup: 在config文件中加入以下节点: [html] view plaincopy print? <configSections> <sectionGroup ...

  2. 自定义配置节 Section

    项目中遇到需求:随时通过增删改配置文件中配置节,来修改程序获取的配置,这里应用到自定义配置节section  type="System.Configuration.NameValueSect ...

  3. C# App.config 自定义 配置节

    方法一. App.config <?xml version="1.0" encoding="utf-8" ?> <configuration& ...

  4. 自定义配置节与配置节的读取

    一.引子 你是否也遇到过这样的问题:项目很多配置都写到了App.Config或Web.Config的AppSettings内,每个人都加了几条,到最后囤积了大量的配置,分不清哪个是有用的.哪个是没用的 ...

  5. 如何在.config文件自定义配置节

    在.NET程序中一般都有个应用程序配置文件在ASP.NET中是web.config,在控制台应用程序和Windows应用程序中是app.config.我们通常使用此配置文件来设置一些程序会用到的信息, ...

  6. 萌新向Python数据分析及数据挖掘 第一章 Python基础 第三节 列表简介 第四节 操作列表...

    第一章 Python基础 第三节 列表简介 列表是是处理一组有序项目的数据结构,即可以在一个列表中存储一个序列的项目.列表中的元素包括在方括号([])中,每个元素之间用逗号分割.列表是可变的数据类型, ...

  7. JPOM - AOP+自定义注解实现操作日志记录

    文章目录 地址 版本 源码解析-AOP+自定义注解实现操作日志记录 地址 Gitee: https://gitee.com/dromara/Jpom 官网: https://jpom.io/ 一款简而 ...

  8. web.config文件之自定义错误节

    web.config文件之自定义错误节 大家都知道,在开发asp.net应用程序时,通过web.config文件可以配置在执行 Web 请求期间发生未处理的错误时,ASP.NET 显示信息的方式.下面 ...

  9. VBS操作IE ---(【当不使用IE时】可以使用Chrome插件,自定义JS插件操作浏览器)

    目录 ■前言 ■举个简单VBS操作IE的例子 --- ■如何让IE打开是IE,而不是Edge ■其他更多VBS相关 ・更多操作一览 ・按键 shift ctrl alt ・打开图片,以幻灯片形式显示 ...

最新文章

  1. c#数据结构———二叉查找树
  2. python:ElementTree操作XML
  3. Laravel 5.1 artisan 的使用
  4. PID算法搞不懂?看这篇文章就够了。
  5. (2021年)IT技术分享社区个人文章汇总(电脑技巧篇)
  6. 前端学习(3329):闭包的形式5
  7. echo输出换行_Bash shell教程[5] echo命令
  8. 使用 show status 命令
  9. 云原生游戏《云联物语》揭开神秘面纱 云鹭科技温向东带你深度了解云原生游戏领域...
  10. 微信小程序input详解
  11. 当安装完Windows系统后出现“系统保留”分区该怎么办?
  12. 武装突袭3多人服务器文件地图,武装突袭3地图文件夹 | 手游网游页游攻略大全...
  13. Use junit to test Trangle problem
  14. Program week9 work
  15. 垃圾收集 (Garbage Collection,GC)
  16. 100!的尾数有多少个零?
  17. RAID的基本工作模式
  18. 小学学校计算机里的单机游戏,15年前的农村小网吧,那个时候只能玩这些单机游戏...
  19. SDNFV Fest论坛成功举办 全景展现SDN/NFV测试成果
  20. AtCoder Beginner Contest 254 A~E 题解

热门文章

  1. spark java8 scala_在 Ubuntu16.04 中搭建 Spark 单机开发环境 (JDK + Scala + Spark)
  2. 工具类的方法怎么引用_Java实用工具类:File工具类方法学习,可创建目录及文件...
  3. 配置中文_《洛克人Zero/ZX遗产合集》PC配置公布 支持中文
  4. 没有域可以加文件服务器吗,文件服务器没有域
  5. 海上瓶子下有东西吗_小小的瓶盖竟有如此大的作用, 闻名不如眼见, 你知道吗?...
  6. cocos2dx ios入口类_2.cocos2d-x 第一个项目
  7. 19年三本毕业,做了三年的嵌入式软件。
  8. PCB上晶振布局是个技术活,避开PCB的边缘很重要
  9. auto与迭代器的用法_C++ STL move_iterator移动迭代器用法详解
  10. python或运算 和 in_Python’的奇怪行为是’运算符,如果与’in’结合使用[复制]