C # How to obtain the project root directory

Source: Internet
Author: User
The project root directory that is often used when programming. Summarize as follows:
1. Obtain the root directory of the console application
Method 1. Environment. currentdirectory gets or sets the full qualified path of the current working directory
Method 2: appdomain. currentdomain. basedirectory gets the base Directory, which is used by the Assembly conflict resolution program to detect the Assembly
2. Obtain the root directory of the Web Application
Method 1: httpruntime. appdomainapppath. tostring (); // obtain the physical drive path of the application directory that hosts the application in the current application domain. Used for obtaining from app_data
Method 2: Server. mappath ("") or server. mappath ("~ /"); // Return the physical file path relative to the specified virtual path on the Web Server
Method 3: request. applicationpath; // obtain the virtual application root directory of ASP. NET applications on the server
3. Obtain the root directory of the winform Application
1. Environment. currentdirectory. tostring (); // gets or sets the fully qualified path of the current working directory
2. Application. startuppath. tostring (); // obtain the path of the executable file that started the application, excluding the name of the executable file
3. Directory. getcurrentdirectory (); // obtain the current working directory of the application
4. appdomain. currentdomain. basedirectory; // obtain the base Directory, which is used by the Assembly conflict resolution program to detect the Assembly
5. appdomain. currentdomain. setupinformation. applicationbase; // obtain or set the name of the directory containing the application.
The following two methods can be used to obtain the name of the execution file:
1. process. getcurrentprocess (). mainmodule. filename; // obtain the file name of the currently executed exe.
2. Application. executablepath; // obtain the path of the executable file that started the application, including the name of the executable file appdomain. currentdomain. basedirectory quartz.

C # How to obtain the project root directory

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.