7 common methods for getting the current path of a program in C #

Source: Internet
Author: User

C #.ProgramCurrent path7The most common method

String str1 = process. getcurrentprocess (). mainmodule. filename ;//Obtain the currently executedEXEFile Name. 

String str2 = environment. currentdirectory ;//Obtain and set the full path of the current directory (that is, the directory from which the process starts.

//Remarks are as defined. if the process is started locally or in the 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 without a backslash (such as"C: \ mysubdirectory").

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

Get and set the current directory(Directory from which the process is started).

3.System. Io. Directory. getcurrentdirectory ()

Obtain the current working directory of the application. This is not necessarily the directory from which the program starts.C: \ wwwLi,This function may returnC: \ Documents ents and Settings \ zyb \,OrC: \ 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. Effect and2,5Same. Just5The returned string is followed by one more"\"Only

7.System. Windows. Forms. application. executablepath

Obtain the path, file name, effect, and1Same

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.