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[]{'/'}); string _FolderPath = ""; for(int i=0;i<arrSection.Length-1;i++) { _FolderPath += arrSection[i] + "/"; } return _FolderPath; }