sectiongroup:
在config文件中加入以下节点:
[html]
view plain
copy
print
?
- <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>
<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 plain
copy
print
?
- 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();
-
- }
-
- }
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 plain
copy
print
?
- <configuration>
-
- <configSections>
- <section name="sampleSection"
- type="System.Configuration.SingleTagSectionHandler" />
- </configSections>
-
- <sampleSection setting1="Value1"
- setting2="value two"
- setting3="third value" />
-
- </configuration>
<configuration>
<configSections>
<section name="sampleSection"
type="System.Configuration.SingleTagSectionHandler" />
</configSections>
<sampleSection setting1="Value1"
setting2="value two"
setting3="third value" />
</configuration>
获取其中的值
[csharp]
view plain
copy
print
?
- Hashtable ht = ConfigurationManager.GetSection("sampleSection") as Hashtable;
-
- 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)