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