close

WinForm應該就是下面這些方式了吧

如果用"C#中獲取程序當前路徑的幾種方法"

關鍵字去找還真的是一堆人有整理呀......

1.取得和設置當前目錄(即該進程從中啟動的目錄)的完全限定路徑。
string str = System.Environment.CurrentDirectory;
結果: C:\xxx\xxx

2.取得啟動了應用程序的可執行文件的路徑,不包括可執行文件的名稱。
string str = System.Windows.Forms.Application.StartupPath;
結果: C:\xxx\xxx

3.取得應用程序的當前工作目錄。
string str = System.IO.Directory.GetCurrentDirectory();
結果: C:\xxx\xxx

4.取得當前 Thread 的當前應用程序域的基目錄,它由程序集衝突解決程序用來探測程序集。
string str = System.AppDomain.CurrentDomain.BaseDirectory;
結果: C:\xxx\xxx\

5.取得和設置包含該應用程序的目錄的名稱。
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
結果: C:\xxx\xxx\

6.取得啟動了應用程序的可執行文件的路徑,包括可執行文件的名稱。
string str = System.Windows.Forms.Application.ExecutablePath;
結果: C:\xxx\xxx\xxx.exe

7.取得當前執行的exe的文件名。
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
結果: C:\xxx\xxx\xxx.exe

8.取得當前進程的完整路徑,包含文件名。
string str = this.GetType().Assembly.Location;
結果: C:\xxx\xxx\xxx.exe

Web的可以參考一下:

http://pramaire.pixnet.net/blog/post/24610352

arrow
arrow
    全站熱搜

    鴨爸 發表在 痞客邦 留言(2) 人氣()