日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

(装载)C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别

發布時間:2023/12/4 C# 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (装载)C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

?

// 獲取程序的基目錄。
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文件中.

?

出處:http://blog.csdn.net/CYSONG168/archive/2010/07/26/5767533.aspx

?

注意下面:

string ? str1 ? =Process.GetCurrentProcess().MainModule.FileName;//可獲得當前執行的exe的文件名。 ? ??
string ? str2=Environment.CurrentDirectory;//獲取和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。?
//備注 ? 按照定義,如果該進程在本地或網絡驅動器的根目錄中啟動,則此屬性的值為驅動器名稱后跟一個尾部反斜杠(如“C:\”)。如果該進程在子目錄中啟動,則此屬性的值為不帶尾部反斜杠的驅動器和子目錄路徑(如“C:\mySubDirectory”)。?
string ? str3=Directory.GetCurrentDirectory();//獲取應用程序的當前工作目錄。?
string ? str4=AppDomain.CurrentDomain.BaseDirectory;//獲取基目錄,它由程序集沖突解決程序用來探測程序集。?
string ? str5=Application.StartupPath;//獲取啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。
string ? str6=Application.ExecutablePath;//獲取啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。?
string ? str7=AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//獲取或設置包含該應用程序的目錄的名稱。

轉載于:https://www.cnblogs.com/9988/articles/2464928.html

總結

以上是生活随笔為你收集整理的(装载)C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。