日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > C# >内容正文

C#

C# WinForm获取 当前执行程序路径的几种方法

發(fā)布時(shí)間:2025/3/20 C# 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# WinForm获取 当前执行程序路径的几种方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn),原文地址:http://blog.csdn.net/yanlele424/article/details/7329389

1.獲取和設(shè)置當(dāng)前目錄的完全限定路徑。

string str = System.Environment.CurrentDirectory;

Result: C:xxxxxx

2.獲取啟動(dòng)了應(yīng)用程序的可執(zhí)行文件的路徑,不包括可執(zhí)行文件的名稱。

string str = System.Windows.Forms.Application.StartupPath;

Result: C:xxxxxx

3.獲取新的 Process 組件并將其與當(dāng)前活動(dòng)的進(jìn)程關(guān)聯(lián)的主模塊的完整路徑,包含文件名。

string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

Result: C:xxxxxxxxx.exe

4.獲取當(dāng)前 Thread 的當(dāng)前應(yīng)用程序域的基目錄,它由程序集沖突解決程序用來(lái)探測(cè)程序集。

string str = System.AppDomain.CurrentDomain.BaseDirectory;

Result: C:xxxxxx

5.獲取應(yīng)用程序的當(dāng)前工作目錄。

string str = System.IO.Directory.GetCurrentDirectory();

Result: C:xxxxxx

6.獲取和設(shè)置包含該應(yīng)用程序的目錄的名稱。

string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

Result: C:xxxxxx

7.獲取當(dāng)前進(jìn)程的完整路徑,包含文件名。

string str = this.GetType().Assembly.Location;

Result: C:xxxxxxxxx.exe

8.獲取啟動(dòng)了應(yīng)用程序的可執(zhí)行文件的路徑,包括可執(zhí)行文件的名稱。

string str = System.Windows.Forms.Application.ExecutablePath;

Result: C:xxxxxxxxx.exe


---------------------------------------------------------------------------------

在dll中有時(shí)需要使用主調(diào)用程序中的資源,這就要正確獲取調(diào)用程序的文件名及其路徑等信息。這需要和調(diào)用dll本身的文件名和路徑區(qū)分開(kāi)來(lái)!

?

?? ?這就牽扯到System.Reflection.Assembly程序集類使用了。

?? ??GetExecutingAssembly?:?獲取包含當(dāng)前執(zhí)行的代碼的程序集

?? ??GetCallingAssembly?:?返回調(diào)用當(dāng)前正在執(zhí)行的方法的方法的 System.Reflection.Assembly

?

轉(zhuǎn)載于:https://www.cnblogs.com/wumingpu/p/5257097.html

總結(jié)

以上是生活随笔為你收集整理的C# WinForm获取 当前执行程序路径的几种方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。