您的位置:首页 > 编程语言 > C#

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

2013-06-26 14:42 302 查看
以下为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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: