c gets the console application root directory

  • 2020-06-12 10:29:58
  • OfStack

1, get the console application root directory method

Environment. CurrentDirectory gets or sets the fully qualified path to the current working directory
AppDomain.CurrentDomain.BaseDirectory gets the base directory used by the assembly resolver to probe the assembly

2. Get the root directory method of Web application

Method 1. HttpRuntime. AppDomainAppPath. ToString(); // Gets the physical drive path of the application directory that hosts the applications in the current application domain. Used for fetching in App_Data
Server. MapPath("") or ES22en. MapPath("~/"); // Returns the physical file path as opposed to the specified virtual path on the Web server
Method 3. Request.ApplicationPath; // Gets the virtual application root for the ES28en. NET application on the server

3. Get the root directory method of WinForm application

1, Environment. CurrentDirectory. ToString (); Gets or sets the fully qualified path to the current working directory
2, Application. StartupPath. ToString (); // Gets the path to the executable that started the application, excluding the name of the executable
3, Directory. GetCurrentDirectory (); Gets the current working directory of the application
4, AppDomain. CurrentDomain. BaseDirectory; // Gets the base directory used by assembly resolver to probe assemblies
5, AppDomain. CurrentDomain. SetupInformation. ApplicationBase; // Gets or sets the name of the directory containing the application

Where: The following two methods get the name of the execution file
1, Process. GetCurrentProcess (). MainModule. FileName; // The file name of exe is available for the current execution.
2, Application. ExecutablePath; // Gets the path to the executable that started the application, including the name of the executable


Related articles: