Application.StartupPath
Application.ExecutablePath
AppDomain.CurrentDomain.BaseDirectory
System.Threading.Thread.GetDomain().BaseDirectory
Environment.CurrentDirectory
System.IO.Directory.GetCurrentDirectory
因为这些方法都是获取宿主程序的绝对路径,而不是Dll文件的路径,其实使用下面的函数就可以了:
//获取DLL自身路径
public string GetDllPath()
{
string dllpath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
dllpath = dllpath.Substring(8, dllpath.Length - 8); // 8是 file:// 的长度
return System.IO.Path.GetDirectoryName(dllpath);
}