| 方法 | 回傳值範例 | 說明 |
|---|---|---|
Environment.CurrentDirectory | C:\xxx\xxx | 目前工作目錄,可讀寫 |
Application.StartupPath | C:\xxx\xxx | 啟動執行檔所在目錄(不含檔名) |
Process.GetCurrentProcess().MainModule.FileName | C:\xxx\xxx\xxx.exe | 完整執行檔路徑含檔名 |
AppDomain.CurrentDomain.BaseDirectory | C:\xxx\xxx\ | 應用程式域基底目錄(含結尾斜線) |
Directory.GetCurrentDirectory() | C:\xxx\xxx | 同 Environment.CurrentDirectory |
AppDomain.CurrentDomain.SetupInformation.ApplicationBase | C:\xxx\xxx\ | 同 BaseDirectory |
this.GetType().Assembly.Location | C:\xxx\xxx\xxx.exe | 當前組件檔案路徑 |
Application.ExecutablePath | C:\xxx\xxx\xxx.exe | 啟動執行檔完整路徑 |
Application.StartupPathApplication.ExecutablePathAssembly.GetExecutingAssembly().LocationHttpRuntime.AppDomainAppPath 或 Server.MapPath("~")實務上常透過 XML 設定檔指定資料、日誌等目錄,避免硬式編碼路徑。