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;
                }


發佈了66 篇原創文章 · 獲贊 5 · 訪問量 27萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章