C# method to call dll to obtain the physical path of dll

大家讲道理
Release: 2016-11-10 14:52:19
Original
1412 people have browsed it

When writing class library projects, there are often some special businesses that need to use the physical path on the server side. Use the traditional The System.IO.Directory.GetCurrentDirectory() method returns the WINNTSystem32 directory, which generally cannot be full. To meet normal business needs, to get the physical directory where the specific running DLL is located, you can use Assembly.GetExecutingAssembly().CodeBase property To obtain it, the specific reference method is as follows:

/// <summary>  
 /// 获取Assembly的运行路径  
 /// </summary>  
 ///<returns></returns>  
 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[]{&#39;/&#39;});             
     string _FolderPath = "";  
     for(int i=0;i<arrSection.Length-1;i++)  
     {  
         _FolderPath += arrSection[i] + "/";  
     }  
     return _FolderPath;  
 }
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!