元素我有一個配置文件,是這樣的:循環遍歷configrationsection讀它使用C#
<logonurls>
<othersettings>
<setting name="DefaultEnv" serializeAs="String">
<value>DEV</value>
</setting>
</othersettings>
<urls>
<setting name="DEV" serializeAs="String">
<value>http://login.dev.server.com/Logon.asmx</value>
</setting>
<setting name="IDE" serializeAs="String">
<value>http://login.ide.server.com/Logon.asmx</value>
</setting>
</urls>
<credentials>
<setting name="LoginUserId" serializeAs="String">
<value>abc</value>
</setting>
<setting name="LoginPassword" serializeAs="String">
<value>123</value>
</setting>
</credentials>
</logonurls>
我怎樣才能讀取配置得到通過的鍵名的值。以下是我寫的方法:
private static string GetKeyValue(string keyname)
{
string rtnvalue = String.Empty;
try
{
ConfigurationSectionGroup sectionGroup = config.GetSectionGroup("logonurls");
foreach (ConfigurationSection section in sectionGroup.Sections)
{
//I want to loop through all the settings element of the section
}
}
catch (Exception e)
{
}
return rtnvalue;
}
config是配置變量,它具有來自配置文件的數據。