C#中AppDomain.CurrentDomain.BaseDirectory與Application.StartupPath的區別 2011-03-08 17:40
// 擷取程式的基目錄。
System.AppDomain.CurrentDomain.BaseDirectory
// 擷取模組的完整路徑。
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 擷取和設定目前的目錄(該進程從中啟動的目錄)的完全限定目錄。
System.Environment.CurrentDirectory
// 擷取應用程式的當前工作目錄。
System.IO.Directory.GetCurrentDirectory()
// 擷取和設定包括該應用程式的目錄的名稱。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 擷取啟動了應用程式的可執行檔的路徑。
System.Windows.Forms.Application.StartupPath
// 擷取啟動了應用程式的可執行檔的路徑及檔案名稱
System.Windows.Forms.Application.ExecutablePath
C# WinForm中AppDomain.CurrentDomain.BaseDirectory與Application.StartupPath的區別樣本如下:
private void Frm_Server_Load(object sender, EventArgs e)
{
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
MessageBox.Show(Application.StartupPath );
}
說明:
1. AppDomain.CurrentDomain.BaseDirectory 返回結果為: D:\mycode\
Application.StartupPath 返回結果為: D:\mycode
2. Application.StartupPath 只能用於WinForm表單中,而AppDomain.CurrentDomain.BaseDirectory既可以用於WinForm表單中,也可以用於類庫DLL檔案中.