您当前的位置: 首页 >  c#

衣舞晨风

暂无认证

  • 0浏览

    0关注

    1156博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C# 调用dll获取dll物理路径的方法

衣舞晨风 发布时间:2015-05-21 11:59:17 ,浏览量:0

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

      /// 
       /// 获取Assembly的运行路径
       /// 
       ///
       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            
关注
打赏
1647422595
查看更多评论
0.0399s