c# 读取*.config文件指定节点的值

以下为config文件中的内容:

<?xml version="1.0" encoding="utf-8"?>
<FileBaseDir xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <BaseDir>/Temp/HeLiuDistFile/</BaseDir>
</FileBaseDir>


c#代码中解析的方式:

 XmlDocument xmlDoc = new XmlDocument();
                string appStartupPath = System.AppDomain.CurrentDomain.BaseDirectory;
                xmlDoc.Load(appStartupPath + @"ConfigurationFiles\ConfigPath\TestConfig.config");//获取配置文件存放的位置
                XmlNode root = xmlDoc.SelectSingleNode("FileBaseDir");
                if (root != null)
                {
                    m_DistFileBaseDir = root.SelectSingleNode("BaseDir").InnerText;
                }


你可能感兴趣的:(C#)