一般情況下,我們通過 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("\\"));
}
}