110,528
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 读取xml文件的appSettings下key的配置项
/// </summary>
/// <param name="sFullName_Config"></param>
/// <param name="sAppKey"></param>
public static string GetCfgValue(string sFullName_Config, string sAppKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
if (!File.Exists(sFullName_Config)) throw new Exception(string.Format("配置文件路径不可用。{0}", sFullName_Config));
xDoc.Load(sFullName_Config);
XmlNode xNode;
XmlElement xElem1;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + sAppKey + "']");
if (xElem1 != null) return xElem1.GetAttribute("value");
}
catch (Exception ex)
{
Logger.WriteLog(string.Format("加载配置文件失败。异常:{0}", ex.Message.ToString()));
}
return "";
}
//调用
string _sFileName = Application.ExecutablePath + ".config";
return GetCfgValue(_sFileName, “你的KEY”);