C# 在AppConfig文件中循环
我有一个AppConfig文件,如下所示:C# 在AppConfig文件中循环,c#,loops,C#,Loops,我有一个AppConfig文件,如下所示: <configuration> <configSections> <sectionGroup name="TableSettings"> <section name="TableNames" type="System.Configuration.DictionarySectionHandler"/> </sectionGroup> </configSe
<configuration>
<configSections>
<sectionGroup name="TableSettings">
<section name="TableNames" type="System.Configuration.DictionarySectionHandler"/>
</sectionGroup>
</configSections>
<TableSettings>
<TableNames>
<add key="Tablename" value="DailyBilling_20131231"/>
<add key="Tablename" value="DailyBilling_20130131"/>
</TableNames>
</TableSettings>
</configuration>
感谢您的帮助
谢谢。试试这个
try
{
string strXML = File.ReadAllText("xml.xml");
XDocument xsrcdoc = XDocument.Parse(strXML);
var KeyValuePairs = (from xml in xsrcdoc.Descendants("add") select
new {
Key = xml.Attribute("key").Value,
value = xml.Attribute("value").Value
}).ToList();
} //Put a break-point here and mouse-over KeyValuePairs and you should see your values....
catch (Exception)
{
throw;
}
我正在从应用程序构建文件夹中的文件(XML.XML)中将XML读入字符串。要使代码正常工作,请将strXML设置为XML或创建XML.XML文件并将XML保存在其中……请查看以下问题的答案:
try
{
string strXML = File.ReadAllText("xml.xml");
XDocument xsrcdoc = XDocument.Parse(strXML);
var KeyValuePairs = (from xml in xsrcdoc.Descendants("add") select
new {
Key = xml.Attribute("key").Value,
value = xml.Attribute("value").Value
}).ToList();
} //Put a break-point here and mouse-over KeyValuePairs and you should see your values....
catch (Exception)
{
throw;
}