1、AppDomain.CurrentDomain.BaseDirectory
using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); Console.ReadLine(); } } }
輸出結果如下:

2 winform里面的Application 類
需要添加System.Windows.Forms.dll引用
獲取啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱
private void Form1_Load(object sender, EventArgs e) { Console.WriteLine(Application.StartupPath); }

3 通過Process類
string strByProcess = Process.GetCurrentProcess().MainModule.FileName; Console.WriteLine("可執行文件路徑:"+strByProcess); Console.WriteLine("啟動目錄:"+Path.GetFileName(strByProcess));

