一般情况下,我们通过 Application.ExecutablePath 来获取,不过Application 位于System.Windows.Forms,这对于非Form应用可能不太方便,另外有一种更通用的方式获取: System.Reflection.Assembly.GetEntryAssembly().Location。
//当前应用路径
public static string AppPath
{
get
{
string exe = System.Reflection.Assembly.GetEntryAssembly().Location;
return exe.Substring(0, exe.LastIndexOf("\\"));
}
}