欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

.NET獲取當前路徑的方法匯總

 更新時間:2016年12月30日 09:52:05   作者:何問起  
本文匯總了.NET(包括ASP.NET/WinForm等)獲取當前路徑的各種方法,具有一定的參考價值,下面跟著小編一起來看下吧

以下匯總了.NET(包括ASP.NET/WinForm等)獲取當前路徑的各種方法

//獲取當前進程的完整路徑,包含文件名(進程名)。  
string str = this.GetType().Assembly.Location;  
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名) 

//獲取新的 Process 組件并將其與當前活動的進程關聯(lián)的主模塊的完整路徑,包含文件名(進程名)。  
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;  
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名) 

//獲取和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。  
string str = System.Environment.CurrentDirectory;  
result: X:\xxx\xxx (.exe文件所在的目錄) 

//獲取當前 Thread 的當前應用程序域的基目錄,它由程序集沖突解決程序用來探測程序集。  
string str = System.AppDomain.CurrentDomain.BaseDirectory;  
result: X:\xxx\xxx\ (.exe文件所在的目錄+"\") 

//獲取和設置包含該應用程序的目錄的名稱。  
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;  
result: X:\xxx\xxx\ (.exe文件所在的目錄+"\") 

//獲取啟動了應用程序的可執(zhí)行文件的路徑,不包括可執(zhí)行文件的名稱。  
string str = System.Windows.Forms.Application.StartupPath;  
result: X:\xxx\xxx (.exe文件所在的目錄) 

//獲取啟動了應用程序的可執(zhí)行文件的路徑,包括可執(zhí)行文件的名稱。  
string str = System.Windows.Forms.Application.ExecutablePath;  
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名) 

//獲取應用程序的當前工作目錄(不可靠)。  
string str = System.IO.Directory.GetCurrentDirectory();  
result: X:\xxx\xxx (.exe文件所在的目錄)

//獲取當前進程的完整路徑,包含文件名(進程名)。
string str = this.GetType().Assembly.Location;
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名)

//獲取新的 Process 組件并將其與當前活動的進程關聯(lián)的主模塊的完整路徑,包含文件名(進程名)。
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名)

//獲取和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。
string str = System.Environment.CurrentDirectory;
result: X:\xxx\xxx (.exe文件所在的目錄)

//獲取當前 Thread 的當前應用程序域的基目錄,它由程序集沖突解決程序用來探測程序集。
string str = System.AppDomain.CurrentDomain.BaseDirectory;
result: X:\xxx\xxx\ (.exe文件所在的目錄+"\")

//獲取和設置包含該應用程序的目錄的名稱。
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
result: X:\xxx\xxx\ (.exe文件所在的目錄+"\")

//獲取啟動了應用程序的可執(zhí)行文件的路徑,不包括可執(zhí)行文件的名稱。
string str = System.Windows.Forms.Application.StartupPath;
result: X:\xxx\xxx (.exe文件所在的目錄)

//獲取啟動了應用程序的可執(zhí)行文件的路徑,包括可執(zhí)行文件的名稱。
string str = System.Windows.Forms.Application.ExecutablePath;
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名)

//獲取應用程序的當前工作目錄(不可靠)。
string str = System.IO.Directory.GetCurrentDirectory();
result: X:\xxx\xxx (.exe文件所在的目錄)

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

//Web編程  
HttpContext.Current.Server.MapPath("FileName")  
System.Web.HttpContext.Current.Request.Path 

//Windows編程  
System.Environment.CurrentDirectory 

//Mobile編程  
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關文章

最新評論