/// <summary>
/// 获取子系统驱动获取DCM配置文件的特定值
/// </summary>
/// <param name="configurationFile"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string ReadValueByKey(ConfigurationFile configurationFile, string key)
{
string value = string.Empty;
string filename = string.Empty;
if (configurationFile.ToString() == ConfigurationFile.AppXml.ToString())
{
//string exeroot = "F:\\DCM\\DLAX.DataCollectorMiddleware\\DLAX.DataCollectorMiddleware\\bin\\Debug\\DeviceLib\\视频子系统\\北京电科院\\BJDKY\\Start.exe";
string exeroot = System.Windows.Forms.Application.ExecutablePath;
if (exeroot.IndexOf("DeviceLib") > 0)
{
string fileroot = exeroot.Substring(0, exeroot.IndexOf("DeviceLib"));
filename = fileroot + "dcm.xml";
}
else
{
filename = System.AppDomain.CurrentDomain.BaseDirectory + "dcm.xml";
}
}
XmlDocument doc = new XmlDocument();
try
{
doc.Load(filename); //加载配置文件
}
catch (Exception ex)
{
return null;
}
XmlNode node = doc.SelectSingleNode("//appSettings"); //得到[appSettings]节点
////得到[appSettings]节点中关于Key的子节点
XmlElement element = (XmlElement)node.SelectSingleNode("//add[@key=‘" + key + "‘]");
if (element != null)
{
value = element.GetAttribute("value");
}
return value;
}
原文地址:https://www.cnblogs.com/yuesebote/p/10916469.html