1. Obtain the path of the current file
String str1 = process. getcurrentprocess (). mainmodule. filename; // Obtain the file name of the currently executed exe.
String str2 = environment. currentdirectory; // Obtain and set the full path of the current directory (that is, the directory from which the process starts. (Note: As defined, if the process is started in the local or root directory of the network drive, the value of this attribute is the drive name followed by a backslash (such as "C: \"). If the process is started in a subdirectory, the value of this attribute is a drive and subdirectory path [such as "C: \ mysubdirectory"] without a backslash.
String str3 = directory. getcurrentdirectory ();// Obtain the current working directory of the application.
String str4 = appdomain. currentdomain. basedirectory; // Obtain the base Directory, which is used by the Assembly conflict resolution program to detect the assembly.
String str5 = application. startuppath; // Obtain the path of the executable file that started the application, excluding the name of the executable file.
String str6 = application. executablepath; // Obtain the path of the executable file that started the application, including the name of the executable file.
String str7 = appdomain. currentdomain. setupinformation. applicationbase; // Obtain or set the name of the directory containing the application.
1. system. Diagnostics. process. getcurrentprocess (). mainmodule. filename
Obtain the complete path of the module.
2. system. environment. currentdirectory
Obtain and set the fully qualified directory of the current directory from which the process starts.
3. system. Io. Directory. getcurrentdirectory ()
Obtain the current working directory of the application. This is not necessarily the directory from which the program starts. It may be stored in c: \ www. This function may return c: \ Documents ents and Settings \ zyb \, or C: \ Program Files \ Adobe \, sometimes not necessarily return anything. This is the last operation directory of any application. For example, if you open the file E: \ doc \ my.doc in word, then, E: \ doc is returned.
4. system. appdomain. currentdomain. basedirectory
Obtain the base Directory of the program.
5. system. Windows. Forms. application. startuppath
Obtain the path of the executable file that started the application. The effect is the same as that of 2 and 5. Only 5 returns an extra "\" after the string.
6. system. Windows. Forms. application. executablepath
Obtain the path and file name of the executable file that started the application. The effect is the same as that of 1.
7. system. appdomain. currentdomain. setupinformation. applicationbase
Obtain and set the name of the directory containing the application.
Ii. Operating Environment Variables
The system. environment. getenvironmentvariable () method can be used to conveniently obtain system environment variables, such as system. environment. getenvironmentvariable ("WINDIR.
The following are common values of environment variables:
System. environment. getenvironmentvariable ("WINDIR ");
System. environment. getenvironmentvariable ("include ");
System. environment. getenvironmentvariable ("tmp ");
System. environment. getenvironmentvariable ("Temp ");
System. environment. getenvironmentvariable ("path ");
3. Application Instances
A winform program is compiled. The project file is stored in D: \ projects \ demo, and the compiled file is in D: \ projects \ demo \ bin \ Debug. The final result is as follows:
1, System. Diagnostics. process. getcurrentprocess (). mainmodule. filename = D: \ projects \ demo \ bin \ debug \ demo.vshost.exe
2, System. environment. currentdirectory = D: \ projects \ demo \ bin \ debug
3, System. Io. Directory. getcurrentdirectory () = D: \ projects \ demo \ bin \ debug
4, System. appdomain. currentdomain. basedirectory = D: \ projects \ demo \ bin \ debug \
5, System. appdomain. currentdomain. setupinformation. applicationbase = D: \ projects \ demo \ bin \ debug \
6, System. Windows. Forms. application. startuppath = D: \ projects \ demo \ bin \ debug
7, System. Windows. Forms. application. executablepath = D: \ projects \ demo \ bin \ debug \ demo. exe
System. environment. getenvironmentvariable ("WINDIR") =C: \ WINDOWS
System. environment. getenvironmentvariable ("include") =C: \ Program Files \ Microsoft Visual Studio. NET 2005 \ SDK \ V2.0 \ include \
System. environment. getenvironmentvariable ("tmp") =C: \ release E ~ 1 \ admini ~ 1 \ locals ~ 1 \ Temp
System. environment. getenvironmentvariable ("Temp") =C: \ release E ~ 1 \ admini ~ 1 \ locals ~ 1 \ Temp
System. environment. getenvironmentvariable ("path") =C: \ windows \ system32; C: \ WINDOWS; c: \ windows \ system32 \ WBEM; C: \ Program Files \ Microsoft SQL Server \ 90 \ tools \ binn \