public string ConfigFile
        {
            get
            {
                if (String.IsNullOrEmpty(_configfile))
                {
                    //string assemblyFile = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    string assemblyFile = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                    _configfile = assemblyFile + ".config";
                }
                return _configfile;
            }
        }

Web应用程序dll获取当前程序集路径问题_其他

 

 

获得config配置信息:

/// <summary>  
/// 获取配置文件的属性  
/// </summary>  
/// <param name="key"></param>  
/// <returns></returns>  
public string GetConnectionStringValue(string key)
{
    string value = string.Empty;

    try
    {
        //if (File.Exists(ConfigFile))
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(ConfigFile);

            XmlNode xNode = xml.SelectSingleNode("//connectionStrings");

            XmlElement element = (XmlElement)xNode.SelectSingleNode("//add[@name='" + key + "']");

            value = element.GetAttribute("connectionString").ToString();
        }
    }
    catch { }

    return value;
}

 

慎于行,敏于思!GGGGGG