C# 獲取當前應用的目錄

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章