C # multiple methods to obtain the file path,

Source: Internet
Author: User

C # multiple methods to obtain the file path,

String str5 = Application. StartupPath; // obtain the path of the executable file that started the Application, excluding the name of the executable file.

 

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 ").

// Http://www.cnblogs.com/sosoft/

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.

Related Article

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.