本文摘自PHP中文网,作者大家讲道理,侵删。
写类库项目时,经常会有某些特殊业务需要用到服务器端的物理路径,使用传统的
System.IO.Directory.GetCurrentDirectory()方法返回的则是WINNT\System32目录,这个一般不能满
足正常的业务需求,而要得到具体运行DLL所在的物理目录可以通过Assembly.GetExecutingAssembly().CodeBase属
性来取得,具体参考方法如下:1 2 3 4 5 6 7 8 9 10 11 | /// <summary>
/// 获取Assembly的运行路径
/// </summary>
///<returns></returns>
private string GetAssemblyPath()
{
string _CodeBase =System.Reflection.Assembly.GetExecutingAssembly().CodeBase ;
_CodeBase = _CodeBase.Substring(8,_CodeBase.Length -8);
string [] arrSection = _CodeBase.Split( new char []{ '/' });
string _FolderPath = "" ;
for ( int i=0;i<arrsection.length-1;i++) {= "" _folderpath= "" += "arrSection[i]" "=" " " ;= "" }= "" return = "" _folderpath;= "" }<= "" pre= "" ><div class = "share layui-clear bdsharebuttonbox bdshare-button-style0-16" data-bd-bind= "1630339887013" ><li><a href= "javascript:;" data-cmd= "weixin" class = "wechat" ><i class = "layui-icon" >?</i>微信</a></li><li><a href= "javascript:;" data-cmd= "more" class = "share-btn" ><i class = "layui-icon" >?</i>分享</a></li></div><img src= "/static/images/article_wechat2021.jpg?1111" style= "margin-top: 30px;" alt= "php中文网最新课程二维码" ><!--<a href= "/k.html" target= "_blank" ><img src= "https://img.php.cn/upload/article/000/000/003/60d557b50f89a276.jpg" style= "margin-top: 30px;" alt= "php中文网直播班" /></a>--><p style= "float:right;font-size:13px;color:#999;" ><span class = "red" >声明:</span>本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理</p><div class = "tags layui-clear" ><li>相关标签:<a href= "/search?word=代码片段,代码分享,php代码分享,java代码分享" target= "_blank" >代码片段,代码分享,PHP代码分享,Java代码分享</a> <a href= "/search?word=ruby代码分享,python代码分享,html代码分享,css代" target= "_blank" >Ruby代码分享,Python代码分享,HTML代码分享,CSS代</a></li><li class = "line" ></li></div><div class = "page layui-clear" ><ul><li>上一篇:<a href= "/csharp-article-339149.html" >C# 操作外部Internet Explorer浏览器</a></li><li>下一篇:<a href= "/csharp-article-339151.html" >C# 识别url是否是网络路径</a></li></ul></div></arrsection.length-1;i++)>
|
相关阅读 >>
auto是什么意思
具体介绍使用c#访问access数据库时,提示找不到可安装的isam(图)
c#tuples(元组)
分享asp.NET学习笔记(3)webpages 布局
一个include命令可以指定多个被包含的文件?
关于datacontractjsonserializer的详细介绍
erp系统是什么
c#实现原图片转缩略图
关于vs2017的详细介绍
安装 .NET framework 3.5出现0x800f081f错误的完美解决办法
更多相关阅读请进入《.NET》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » C# 调用dll获取dll物理路径的方法