C # obtain the path of the current application

Source: Internet
Author: User
C # obtain the path of the current application string str1 = process. getcurrentprocess (). mainmodule. filename; // obtain the file name of the currently executed 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.
// The remarks are 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; // gets 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 I don't know what to return.
4. system. appdomain. currentdomain. basedirectory
Obtain the base Directory of the program.
5. system. appdomain. currentdomain. setupinformation. applicationbase
Obtain and set the name of the directory containing the application.
6. system. Windows. Forms. application. startuppath
Obtain the path of the executable file that started the application. Same effect. The returned string is followed by an extra "\".
7. system. Windows. Forms. application. executablepath
Obtain the path and file name of the executable file that started the application. The effect is the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.