zoukankan      html  css  js  c++  java
  • Web应用程序dll获取当前程序集路径问题

    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;
                }
            }

    获得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
  • 相关阅读:
    spark shuffle 机制
    hive explain 源码分析
    前端jQurey
    js-dom操作
    前端JS
    前端CSS
    Redis和MongoDB区别
    MySQL数据库备份
    MySQL索引
    python连接mysql服务端
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/14413713.html
Copyright © 2011-2022 走看看