public class ConfigHelper
{
private static readonly string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.xml");
public static string GetValueByKey(string key, string node = "appSettings")
{
string value = "";
if (File.Exists(path))
{
try
{
var doc = new XmlDocument();
doc.Load(path);
XmlNode xmlNode = doc.SelectSingleNode(node);
if (xmlNode != null)
{
string n = xmlNode.OuterXml.Trim();
var xml = XElement.Parse(n);
var dic = xml.Descendants("add").ToDictionary(x => x.Attribute("key").Value, x => x.Attribute("value").Value);
if (dic.Count > 0)
{
if (dic[key] != "")
{
value = dic[key];
}
}
return value;
}
}
catch (Exception ex)
{
}
}
return "";
}
}