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
  • 相关阅读:
    PHP的GD库
    PHP正则表达式
    Redis学习笔记
    C++的vector对象
    Python的with用法理解
    python 类属性与方法
    python lambda表达式
    Python3的decode()与encode()
    PHP的魔法方法__set() __get()
    MySQL的基本知识 -- 函数
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/14413713.html
Copyright © 2011-2022 走看看