C#獲取文件的絕對路徑

要在c#中獲取路徑有好多方法,一般常用的有以下五種:

//獲取應用程序的當前工作目錄。
String path1 = System.IO.Directory.GetCurrentDirectory();           
MessageBox.Show("獲取應用程序的當前工作目錄:" + path1);

//獲取程序的基目錄。
String path2 = System.AppDomain.CurrentDomain.BaseDirectory;       
MessageBox.Show("獲取程序的基目錄:" + path2);

//獲取和設置包括該應用程序的目錄的名稱。
String path3 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;           
MessageBox.Show("獲取和設置包括該應用程序的目錄的名稱:" + path3);

//獲取啓動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。
String path4 = System.Windows.Forms.Application.StartupPath;          
MessageBox.Show("獲取啓動了應用程序的可執行文件的路徑,不包括可執行文件的名稱:" + path4);

//獲取啓動了應用程序的可執行文件的路徑及文件名
String path5 = System.Windows.Forms.Application.ExecutablePath;          
MessageBox.Show("獲取啓動了應用程序的可執行文件的路徑及文件名:" + path5);

 

 

來自:http://hi.baidu.com/2581550/blog/item/b9ec662a5d9f2925d42af180.html

發佈了26 篇原創文章 · 獲贊 7 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章