zoukankan      html  css  js  c++  java
  • 获取Assembly的运行路径

    在写类库项目时,经常会有某些特殊业务需要用到服务器端的物理路径,使用传统的System.IO.Directory.GetCurrentDirectory()方法返回的则是WINNT\System32目录,这个一般不能满足正常的业务需求,而要得到具体运行DLL所在的物理目录可以通过Assembly.GetExecutingAssembly().CodeBase属性来取得,具体参考方法如下:

    private string GetAssemblyPath()
            {
                string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase ;

                _CodeBase = _CodeBase.Substring(8,_CodeBase.Length - 8);    // 8是 file:// 的长度

                string[] arrSection = _CodeBase.Split(new char[]{'/'});
               
                string _FolderPath = "";
                for(int i=0;i<arrSection.Length-1;i++)
                {
                    _FolderPath += arrSection[i] + "/";
                }

                return _FolderPath;
            }

     

    public static string GetAssemblyPath()
    {
     string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase ;

     _CodeBase = _CodeBase.Substring(8, _CodeBase.LastIndexOf("/")-8+1); // 8是 "file://" 的长度

     return _CodeBase.Replace("/", @"\");
    }

  • 相关阅读:
    (转)一台服务器安装两个tomcat6 服务的解决方案
    目标的改变
    常用但易忘的sql语句及java程序
    数据可视化工具 Gephi
    R中library和require的区别
    python BeautifulSoup解决中文乱码问题
    【转载】MySQL全文检索笔记
    poj 1011
    Nest,很酷的东西
    H.264开源解码器评测
  • 原文地址:https://www.cnblogs.com/perfect/p/1207708.html
Copyright © 2011-2022 走看看