首页 > 代码库 > C#配置文件中怎么通过key来获取value值

C#配置文件中怎么通过key来获取value值

public static string AppConfig()
{
  return System.IO.Path.Combine(Application.StartupPath, "BlackBoxForms.exe.config");
}

 

/// <summary>
/// 根据Key获取Value值
/// </summary>
/// <param name="appKey">Key</param>
/// <returns>Value值</returns>
public static string GetValueByKey(string appKey)
{
  try
  {
    string xmlValuehttp://www.mamicode.com/= "";
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(AppConfig());
    XmlNode xNode = xmlDoc.SelectSingleNode("//appSettings");
    foreach (XmlNode node in xNode.ChildNodes)
    {
    if (node.Attributes["key"].Value =http://www.mamicode.com/= appKey)
    {
      xmlValue = http://www.mamicode.com/node.Attributes["value"].Value;
    }
  }
    return xmlValue;
  }
  catch (Exception ex)
  {
    return ex.Message;
  }
}

C#配置文件中怎么通过key来获取value值