C# 获取应用程序物理地址(运行DLL的物理地址)

来源:互联网 发布:win10打不开任何软件 编辑:程序博客网 时间:2024/06/10 04:57
  1. /// <summary>  
  2. /// 获取Assembly的运行路径  
  3. /// </summary>  
  4. ///<returns></returns>  
  5. private string GetAssemblyPath()  
  6. {  
  7.     string _CodeBase =System.Reflection.Assembly.GetExecutingAssembly().CodeBase ;  
  8.   
  9.     _CodeBase = _CodeBase.Substring(8,_CodeBase.Length -8);    // 8是file:// 的长度  
  10.   
  11.     string[] arrSection = _CodeBase.Split(new char[]{'/'});  
  12.       
  13.     string _FolderPath = "";  
  14.     for(int i=0;i<arrSection.Length-1;i++)  
  15.     {  
  16.         _FolderPath += arrSection[i] + "/";  
  17.     }  
  18.   
  19.     return _FolderPath;  
  20. }  
原创粉丝点击