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>
获取其中的值
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>
获取其中的值
Hashtable ht = ConfigurationManager.GetSection("sampleSection") as Hashtable;
string str1=ht["setting1"];
http://technet.microsoft.com/zh-cn/magazine/ms228245(VS.90).aspx