【轉】C#(ASP.Net)擷取當前路徑的方法集合

來源:互聯網
上載者:User

標籤:

轉自:http://www.gaobo.info/read.php/660.htm

 

[c-sharp] view plaincopy 
  1. //擷取當前進程的完整路徑,包含檔案名稱(進程名)。  
  2. string str = this.GetType().Assembly.Location;  
  3. result: X:/xxx/xxx/xxx.exe (.exe檔案所在的目錄+.exe檔案名稱)  
  4. //擷取新的 Process 組件並將其與當前活動的進程關聯的主模組的完整路徑,包含檔案名稱(進程名)。  
  5. string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;  
  6. result: X:/xxx/xxx/xxx.exe (.exe檔案所在的目錄+.exe檔案名稱)  
  7. //擷取和設定目前的目錄(即該進程從中啟動的目錄)的完全限定路徑。  
  8. string str = System.Environment.CurrentDirectory;  
  9. result: X:/xxx/xxx (.exe檔案所在的目錄)  
  10. //擷取當前 Thread 的當前應用程式定義域的基目錄,它由程式集衝突解決程式用來探測程式集。  
  11. string str = System.AppDomain.CurrentDomain.BaseDirectory;  
  12. result: X:/xxx/xxx/ (.exe檔案所在的目錄+"/")  
  13. //擷取和設定包含該應用程式的目錄的名稱。  
  14. string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;  
  15. result: X:/xxx/xxx/ (.exe檔案所在的目錄+"/")  
  16. //擷取啟動了應用程式的可執行檔的路徑,不包括可執行檔的名稱。  
  17. string str = System.Windows.Forms.Application.StartupPath;  
  18. result: X:/xxx/xxx (.exe檔案所在的目錄)  
  19. //擷取啟動了應用程式的可執行檔的路徑,包括可執行檔的名稱。  
  20. string str = System.Windows.Forms.Application.ExecutablePath;  
  21. result: X:/xxx/xxx/xxx.exe (.exe檔案所在的目錄+.exe檔案名稱)  
  22. //擷取應用程式的當前工作目錄(不可靠)。  
  23. string str = System.IO.Directory.GetCurrentDirectory();  
  24. result: X:/xxx/xxx (.exe檔案所在的目錄)  

 

.NET中三種擷取當前路徑的代碼

 

[c-sharp] view plaincopy 
  1. //Web編程  
  2. HttpContext.Current.Server.MapPath("FileName")  
  3. System.Web.HttpContext.Current.Request.Path  
  4. //Windows編程  
  5. System.Environment.CurrentDirectory  
  6. //Mobile編程  
  7. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);  

 

【轉】C#(ASP.Net)擷取當前路徑的方法集合

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.