麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

ASP.NET總結(jié)C#中7種獲取當(dāng)前路徑的方法

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

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

//獲取模塊的完整路徑。string path1 = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;//獲取和設(shè)置當(dāng)前目錄(該進(jìn)程從中啟動的目錄)的完全限定目錄string path2 = System.Environment.CurrentDirectory;//獲取應(yīng)用程序的當(dāng)前工作目錄string path3 = System.IO.Directory.GetCurrentDirectory();//獲取程序的基目錄string path4 = System.AppDomain.CurrentDomain.BaseDirectory;//獲取和設(shè)置包括該應(yīng)用程序的目錄的名稱string path5 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//獲取啟動了應(yīng)用程序的可執(zhí)行文件的路徑string path6 = System.Windows.Forms.Application.StartupPath;//獲取啟動了應(yīng)用程序的可執(zhí)行文件的路徑及文件名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();

/*  輸出結(jié)果

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



發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 一级在线观看视频 | 国产做爰全免费的视频黑人 | 欧美 videos粗暴 | 91av原创| 国产精品欧美久久久久一区二区 | 香蕉成人在线视频 | 中文字幕激情视频 | 成人激情综合网 | 国产一国产精品一级毛片 | 亚洲爱爱网站 | 国产一及毛片 | 亚洲成人在线视频网 | 欧美日韩色 | 成人三级电影在线 | 特级黄色影院 | 看黄在线观看 | 欧美淫视频 | 久久精品中文字幕一区二区 | 国产精品久久久av | 欧美一级棒 | 91久久一区 | 天天草天天干天天 | 亚洲成人福利在线 | 天天鲁在线视频免费观看 | 欧美高清一级片 | 天堂成人国产精品一区 | 最新中文字幕日本 | 操你啦免费视频 | 一级做a在线观看 | 成人在线第一页 | 中文字幕在线观看视频www | 国产无遮挡一级毛片 | 欧美xxxwww | 成人免费在线观看视频 | 精品国产高清一区二区三区 | 九九热久久免费视频 | 久久精品视频在线 | 一级黄色片武则天 | 在线观看中文字幕av | 久草手机视频在线观看 | 国产亚洲精品久久久久久网站 |