1. 程式人生 > >C#獲取當前路徑的七種方法

C#獲取當前路徑的七種方法

filename ces cut lease rect 包括 name system file

//1.獲取模塊的完整路徑。  
string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;  

//2.獲取和設置當前目錄(該進程從中啟動的目錄)的完全限定目錄  
string path2 = System.Environment.CurrentDirectory;  

//3.獲取應用程序的當前工作目錄  
string path3 = System.IO.Directory.GetCurrentDirectory();  

//4.獲取程序的基目錄  
string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
 
//5.獲取和設置包括該應用程序的目錄的名稱 string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; //6.獲取啟動了應用程序的可執行文件的路徑 string path6 = System.Windows.Forms.Application.StartupPath; //7.獲取啟動了應用程序的可執行文件的路徑及文件名 string path7 = System.Windows.Forms.Application.ExecutablePath; // 輸出結果 1
. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.vshost.exe 2. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release 3. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release 4. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\ 5. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\ 6
. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release 7. D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.EXE

C#獲取當前路徑的七種方法