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);
}
获取动态链接库文件所在路径的方法
本文介绍如何在.NET程序中获取动态链接库文件的路径,包括使用特定函数实现的方法,以及避免常见错误路径获取策略。
733

被折叠的 条评论
为什么被折叠?



