This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16916|Reply: 0

[Source] ASP.NET a collection of methods to get the root directory

[Copy link]
Posted on 10/10/2015 9:57:44 AM | | |

When writing a program, the project root directory that is often used is summarized as follows:
1. Obtain the root directory method of the console application
Method 1: Environment.CurrentDirectory to obtain or set the complete qualified path of the current working directory
Method 2: AppDomain.CurrentDomain.BaseDirectory obtains the base directory, which is used by the assembly conflict solver to probe the assembly
2. Obtain the root directory method of the web application
Method 1, HttpRuntime.AppDomainAppPath.ToString(); Gets the physical drive path to the application directory of the application hosted in the current application domain. Used for App_Data acquisition
Method 2: Server.MapPath("") or Server.MapPath("~/"); Returns a physical file path opposite to the specified virtual path on the web server
Method 3, Request.ApplicationPath; Obtain the virtual application root of the ASP.NET application on the server
3. Obtain the root directory method of the WinForm application
1、Environment.CurrentDirectory.ToString(); Get or set a fully qualified path to the current working directory
2、Application.StartupPath.ToString(); Get the path to the executable file that started the application, excluding the name of the executable
3、Directory.GetCurrentDirectory(); Get the current working directory of the application
4、AppDomain.CurrentDomain.BaseDirectory; Obtain the base directory, which is used by the assembly conflict solver to probe the assembly
5、AppDomain.CurrentDomain.SetupInformation.ApplicationBase; Get or set the name of the directory that contains the application
The following two methods can obtain the name of the execution file
1、Process.GetCurrentProcess(). MainModule.FileName; You can get the file name of the exe that is currently being executed.
2、Application.ExecutablePath; Get the path to the executable file that started the application, including the name of the executable




Previous:Verification fails for one or more entities. For more information, see the EntityValidationErrors property.
Next:C# writes and reads out text files
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com