最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年03月28日 09:19:04   作者:Masonlu  
本文主要介紹了7種獲取當前路徑的方法,并做了代碼演示,分享給大家,感興趣的朋友可以參考一下。

1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 
-獲取模塊的完整路徑。 
2. System.Environment.CurrentDirectory 
-獲取和設(shè)置當前目錄(該進程從中啟動的目錄)的完全限定目錄。 
3. System.IO.Directory.GetCurrentDirectory() 
-獲取應(yī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è)置當前目錄(該進程從中啟動的目錄)的完全限定目錄
string path2 = System.Environment.CurrentDirectory;
//獲取應(yī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   
*/

相關(guān)文章

最新評論

塔城市| 荥经县| 石景山区| 大竹县| 滕州市| 利川市| 江陵县| 大兴区| 阳新县| 利辛县| 佛坪县| 齐齐哈尔市| 巴林右旗| 金川县| 富蕴县| 福建省| 东阳市| 广安市| 鹤岗市| 托克逊县| 鹰潭市| 阳春市| 丹阳市| 义马市| 都兰县| 繁昌县| 上栗县| 赞皇县| 福清市| 佳木斯市| 牙克石市| 峨山| 鹤庆县| 黄冈市| 彭州市| 获嘉县| 孝感市| 宜春市| 晋中市| 莒南县| 渑池县|