C 各種啟動路徑

2021-09-17 08:38:19 字數 874 閱讀 1768

environment.currentdirectory //winform web都可用,當前程式的啟動目錄,如:web就啟動在iis下面。

c#獲取專案程式及執行路徑的方

2.c# winform用

d:「system.threading.thread.getdomain().basedirectory」:獲取當前應用程式所在目錄的路徑,最後包含「\」;

e:「environment.currentdirectory」:獲取當前應用程式的路徑,最後不包含「\」;

f:「system.io.directory.getcurrentdirectory」:獲取當前應用程式的路徑,最後不包含「\」;

用「environment.currentdirectory」和「system.io.directory.getcurrentdirectory」將得到「 system32」目錄的路徑;

4.在解除安裝程式獲取系統安裝的目錄:

system.reflection.assembly curpath = system.reflection.assembly.getexecutingassembly();

string path=curpath.location;//得到安裝程式類setuplibrary檔案的路徑,獲取這個檔案路徑所在的目錄即得到安裝程式的目錄;

system.diagnostics.stackframe f = new system.diagnostics.stackframe(1);

methodbase mb = f.getmethod();

system.web.httpcontext.current.response.write(mb.declaringtype.tostring()); 獲取呼叫類的資訊,可以從父類知道子類的情況

C 中各種路徑

獲取程式的基目錄。獲取模組的完整路徑,包含檔名 system.diagnostics.process.getcurrentprocess mainmodule.filename 獲取和設定當前目錄 該程序從中啟動的目錄 的完全限定目錄。system.environment.currentdirect...

c 中各種獲取路徑方法

獲取模組的完整路徑,包含檔名 system.diagnostics.process.getcurrentprocess mainmodule.filename 獲取和設定當前目錄 該程序從中啟動的目錄 的完全限定目錄。system.environment.currentdirectory 獲取應用程...

C 各種相對路徑

獲取當前可執行的exe的檔名 string str1 process.getcurrentprocess mainmodule.filename 獲取或設定當前目錄 string str2 environment.currentdirectory 獲取應用程式的當前工作目錄 string str3 ...