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

View: 17392|Reply: 0

[ASP.NET] ASP.NET a collection of methods to obtain the project root directory

[Copy link]
Posted on 3/12/2015 11:22:52 PM | | |
1. Obtain the root directory method of the console application
     Method 1, Environment.CurrentDirectory//取得或设置当前工作目录的完整限定路径
     Method 2: AppDomain.CurrentDomain.BaseDirectory//获取基目录,它由程序集冲突解决程序用来探测程序集
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("~/");//返回与Web服务器上的指定的虚拟路径相对的物理文件路径
Method 3, Request.ApplicationPath;//获取服务器上ASP.NET应用程序的虚拟应用程序根目录
3. Obtain the root directory method of the WinForm application
Method 1, Environment.CurrentDirectory.ToString();//获取或设置当前工作目录的完全限定路径
Method 2, Application.StartupPath.ToString();Get the path to the executable file that started the application, excluding the name of the executable     
Method 3, Directory.GetCurrentDirectory();//获取应用程序的当前工作目录
Method 4: AppDomain.CurrentDomain.BaseDirectory;//获取基目录,它由程序集冲突解决程序用来探测程序集
Method 5: AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//获取或设置包含该应用程序的目录的名称
The following two methods can obtain the name of the execution file
1、Process.GetCurrentProcess(). MainModule.FileName;//可获得当前执行的exe的文件名。
2、Application.ExecutablePath;//获取启动了应用程序的可执行文件的路径,包括可执行文件的名称




Previous:What does the school's diligent inspection worker do? Cleaning, or what is responsible, whether there is wood and money, whether it is linked to technology
Next:ORACLE Question Bank and Answers (Chapters 1-4)
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