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("\\"));
    }
}

 

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