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

首頁 > 編程 > C# > 正文

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

2020-01-24 01:13:24
字體:
來源:轉載
供稿:網友

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   
*/

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平顶山市| 广宁县| 龙陵县| 商城县| 长武县| 樟树市| 静乐县| 临泽县| 长治市| 文化| 绥棱县| 剑河县| 鄂伦春自治旗| 玉林市| 栾川县| 勃利县| 江阴市| 区。| 民丰县| 威信县| 荃湾区| 手机| 涡阳县| 托里县| 松江区| 博野县| 南丹县| 广饶县| 吐鲁番市| 昔阳县| 塘沽区| 顺义区| 拉萨市| 精河县| 榆社县| 遂平县| 彭水| 高平市| 焉耆| 九江县| 陵水|