1. 程式人生 > 其它 >C# 獲取當前路徑7種方法及輸出

C# 獲取當前路徑7種方法及輸出

//獲取模組的完整路徑。
string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.vshost.exe

//獲取和設定當前目錄(該程序從中啟動的目錄)的完全限定目錄
string path2 = System.Environment.CurrentDirectory;
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release

//獲取應用程式的當前工作目錄
string path3 = System.IO.Directory.GetCurrentDirectory();
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release

//獲取程式的基目錄
string path4 = System.AppDomain.CurrentDomain.BaseDirectory;
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\

//獲取和設定包括該應用程式的目錄的名稱
string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\

//獲取啟動了應用程式的可執行檔案的路徑
string path6 = System.Windows.Forms.Application.StartupPath;
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release

//獲取啟動了應用程式的可執行檔案的路徑及檔名
string path7 = System.Windows.Forms.Application.ExecutablePath;
D:\work\prj\VP-VPlatform\XmlAndXsd\bin\Release\XmlAndXsd.EXE