C# 獲取目錄路徑


Console.WriteLine(System.Windows.Forms.Application.StartupPath);//獲取啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。(Windows From應用程序才有效)
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug

Console.WriteLine(System.Environment.CurrentDirectory);//獲取或設置當前工作目錄的完全限定路徑。
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug

Console.WriteLine(System.IO.Directory.GetCurrentDirectory());//獲取應用程序的當前工作目錄。
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug

Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);//獲取基目錄,它由程序集沖突解決程序用來探測程序集。
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug\

Console.WriteLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase);//獲取或設置包含該應用程序的目錄的名稱。
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug\

Console.WriteLine(System.Windows.Forms.Application.ExecutablePath);//獲取啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。(Windows From應用程序才有效)
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug\GetPath.EXE

Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);//獲取模塊的完整路徑。
//輸出結果:C:\GetPathInfo\GetPath\bin\Debug\GetPath.vshost.exe

此處項目路徑是:C:\GetPathInfo\


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM