国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET總結C#中7種獲取當前路徑的方法

2024-07-10 13:30:05
字體:
來源:轉載
供稿:網友
本文主要介紹了7種獲取當前路徑的方法,并做了代碼演示,分享給大家,感興趣的朋友可以參考一下。
 

1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName  
-獲取模塊的完整路徑。  
2. System.Environment.CurrentDirectory  
-獲取和設置當前目錄(該進程從中啟動的目錄)的完全限定目錄。  
3. System.IO.Directory.GetCurrentDirectory()  
-獲取應用程序的當前工作目錄。這個不一定是程序從中啟動的目錄啊,有可能程序放在C:/www里,這個函數有可能返回C:/Documents and Settings/ZYB/,或者C:/Program Files/Adobe/,有時不一定返回什么東東,我也搞不懂了。  
4. System.AppDomain.CurrentDomain.BaseDirectory  
-獲取程序的基目錄。  
5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase  
-獲取和設置包括該應用程序的目錄的名稱。  
6. System.Windows.Forms.Application.StartupPath  
-獲取啟動了應用程序的可執行文件的路徑。效果和2、5一樣。只是5返回的字符串后面多了一個"/"而已  
7. System.Windows.Forms.Application.ExecutablePath  
-獲取啟動了應用程序的可執行文件的路徑及文件名,效果和1一樣。 

//獲取模塊的完整路徑。string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;//獲取和設置當前目錄(該進程從中啟動的目錄)的完全限定目錄string path2 = System.Environment.CurrentDirectory;//獲取應用程序的當前工作目錄string path3 = System.IO.Directory.GetCurrentDirectory();//獲取程序的基目錄string path4 = System.AppDomain.CurrentDomain.BaseDirectory;//獲取和設置包括該應用程序的目錄的名稱string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//獲取啟動了應用程序的可執行文件的路徑string path6 = System.Windows.Forms.Application.StartupPath;//獲取啟動了應用程序的可執行文件的路徑及文件名string path7 = System.Windows.Forms.Application.ExecutablePath;StringBuilder str=new StringBuilder();str.AppendLine("System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName:" + path1);str.AppendLine("System.Environment.CurrentDirectory:" + path2);str.AppendLine("System.IO.Directory.GetCurrentDirectory():" + path3);str.AppendLine("System.AppDomain.CurrentDomain.BaseDirectory:" + path4);str.AppendLine("System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:" + path5);str.AppendLine("System.Windows.Forms.Application.StartupPath:" + path6);str.AppendLine("System.Windows.Forms.Application.ExecutablePath:" + path7);string allPath = str.ToString();

/*  輸出結果

System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName:D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release/XmlAndXsd.vshost.exe
System.Environment.CurrentDirectory:D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release
System.IO.Directory.GetCurrentDirectory():D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release
System.AppDomain.CurrentDomain.BaseDirectory:D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release/
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase:D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release/
System.Windows.Forms.Application.StartupPath:D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release
System.Windows.Forms.Application.ExecutablePath:D:/work/prj/VP-VPlatform/XmlAndXsd/bin/Release/XmlAndXsd.EXE    
*/



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 香港 | 泸溪县| 普陀区| 恩施市| 囊谦县| 银川市| 赞皇县| 龙口市| 乌审旗| 南城县| 原阳县| 普格县| 舞钢市| 满城县| 离岛区| 新巴尔虎右旗| 岚皋县| 思南县| 那曲县| 丰原市| 阳春市| 大化| 库尔勒市| 河曲县| 兴安县| 榆中县| 登封市| 萍乡市| 南靖县| 任丘市| 石台县| 洱源县| 福泉市| 太原市| 鄄城县| 乐东| 楚雄市| 兴仁县| 江津市| 临朐县| 渭源县|