A log program recently used the method for obtaining the Application Path. By the way, I sorted it out:
1.20.path with .exe
String str1 = process. getcurrentprocess (). mainmodule. filename; // obtain the file name of the currently executed exe. D: \ work \ projects \ addressmapping \ test \ bin \ debug \ test.vshost.exe
String str1 = application. executablepath; // obtain the path of the executable file that started the application, including the name of the executable file. D: \ work \ projects \ addressmapping \ test \ bin \ debug \ test. exe
String str1 = assembly. getexecutingassembly (). Location; // obtain the path of the executable file that started the application, including the name of the executable file. D: \ work \ projects \ addressmapping \ test \ bin \ debug \ test.exe [Recommended. the full path of the DLL is obtained regardless of the situation]
2.20.remove the path of .exe (\)
String str2 = environment. currentdirectory; // gets and sets the fully qualified path of the current directory (that is, the directory from which the process starts. D: \ work \ projects \ addressmapping \ test \ bin \ debug
For Windows Services, the path c: \ windows \ system32 is used.
String str2 = directory. getcurrentdirectory (); // obtain the current working directory of the application. D: \ work \ projects \ addressmapping \ test \ bin \ debug
For Windows Services, the path c: \ windows \ system32 is used.
String str2 = application. startuppath; // obtain the path of the executable file that started the application, excluding the name of the executable file. D: \ work \ projects \ addressmapping \ test \ bin \ debug
3.6.2 path (with \) for dropping .exe \)
String str3 = appdomain. currentdomain. basedirectory; // gets the base Directory, which is used by the Assembly conflict resolution program to detect the assembly. D: \ work \ projects \ addressmapping \ test \ bin \ debug \
String str3 = appdomain. currentdomain. setupinformation. applicationbase; // obtain or set the name of the directory containing the application. D: \ work \ projects \ addressmapping \ test \ bin \ debug \