C#获取当前程序运行路径的方法集合
生活随笔
收集整理的這篇文章主要介紹了
C#获取当前程序运行路径的方法集合
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//獲取當(dāng)前進(jìn)程的完整路徑,包含文件名(進(jìn)程名)。
string str = this.GetType().Assembly.Location;
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名)//獲取新的 Process 組件并將其與當(dāng)前活動的進(jìn)程關(guān)聯(lián)的主模塊的完整路徑,包含文件名(進(jìn)程名)。
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名)//獲取和設(shè)置當(dāng)前目錄(即該進(jìn)程從中啟動的目錄)的完全限定路徑。
string str = System.Environment.CurrentDirectory;
result: X:\xxx\xxx (.exe文件所在的目錄)//獲取當(dāng)前 Thread 的當(dāng)前應(yīng)用程序域的基目錄,它由程序集沖突解決程序用來探測程序集。
string str = System.AppDomain.CurrentDomain.BaseDirectory;
result: X:\xxx\xxx\ (.exe文件所在的目錄+"\")//獲取和設(shè)置包含該應(yīng)用程序的目錄的名稱。(推薦)
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
result: X:\xxx\xxx\ (.exe文件所在的目錄+"\")//獲取啟動了應(yīng)用程序的可執(zhí)行文件的路徑,不包括可執(zhí)行文件的名稱。
string str = System.Windows.Forms.Application.StartupPath;
result: X:\xxx\xxx (.exe文件所在的目錄)//獲取啟動了應(yīng)用程序的可執(zhí)行文件的路徑,包括可執(zhí)行文件的名稱。
string str = System.Windows.Forms.Application.ExecutablePath;
result: X:\xxx\xxx\xxx.exe (.exe文件所在的目錄+.exe文件名)//獲取應(yīng)用程序的當(dāng)前工作目錄(不可靠)。
string str = System.IO.Directory.GetCurrentDirectory();
result: X:\xxx\xxx (.exe文件所在的目錄) View Code轉(zhuǎn)載自蘋果味的博客http://www.cnblogs.com/CSharpLover/p/5969017.html
轉(zhuǎn)載于:https://www.cnblogs.com/xakml/p/7059747.html
總結(jié)
以上是生活随笔為你收集整理的C#获取当前程序运行路径的方法集合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: POJ 2296 Map Labeler
- 下一篇: Ubuntu 14.04 hadoop单