XmlTextReader reader = new XmlTextReader(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Web.config"));
reader.MoveToContent();
XmlDocument configDoc = new XmlDocument();
configDoc.LoadXml(reader.ReadOuterXml());
XmlNodeList nodeList = configDoc.SelectSingleNode("/configuration/connectionStrings").ChildNodes;
List<string> list = new List<string>();
foreach (XmlNode node in nodeList)
{
//排除注释内容,这里读取的是 <add name="databaseName" connectionString=“”/>的name
if (node.NodeType != XmlNodeType.Comment)
list.Add(node.Attributes["name"].Value);
}
C#读取WebConfig
最新推荐文章于 2024-01-03 17:25:51 发布