//需要读取的配置文件
string configFile = startupPath + "\\" + Properties.Settings.Default.ConfigFileName;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(configFile);
string n1,n2,n3;
XmlDocument xDoc = new XmlDocument();
xDoc.Load(configFile);
XmlNodeList nodeList = xDoc.GetElementsByTagName("setting");
foreach (object obj in nodeList)
{
XmlNode item = (XmlNode)obj;
XmlAttributeCollection xmlAttributeCollection = item.Attributes;
if (xmlAttributeCollection != null)
{
XmlAttribute att = xmlAttributeCollection["name"];
if (att.Value == "v1")
{
n1 = item.SelectSingleNode("value").InnerText;
}
if (att.Value == "v2")
{
n2 = item.SelectSingleNode("value").InnerText;
}
if (att.Value == "v3")
{
n3 = item.SelectSingleNode("value").InnerText;
}
}
}
C#读取.exe.config格式文件
于 2023-07-28 17:26:24 首次发布