. NET method summary for obtaining the current path,. net current path Summary
The following describes how to obtain the current path using. NET (including ASP. NET/WinForm ).
// Obtain the complete path of the current process, including the file name (process name ).
String str = this. GetType (). Assembly. Location;
Result: X: \ xxx \ xxx.exe (.exefile directory. .exe file name)
// Obtain the complete path of the new Process component and associate it with the active Process, including the file name (Process name ).
String str = System. Diagnostics. Process. GetCurrentProcess (). MainModule. FileName;
Result: X: \ xxx \ xxx.exe (.exefile directory. .exe file name)
// Obtain and set the full path of the current directory (that is, the directory from which the process starts.
String str = System. Environment. CurrentDirectory;
Result: X: \ xxx (directory of the .exe file)
// Obtain the base Directory of the current application domain of the current Thread, which is used by the Assembly conflict resolution program to detect the assembly.
String str = System. AppDomain. CurrentDomain. BaseDirectory;
Result: X: \ xxx \ (directory where the .exe file is located + "\")
// Obtain and set the name of the directory containing the application.
String str = System. AppDomain. CurrentDomain. SetupInformation. ApplicationBase;
Result: X: \ xxx \ (directory where the .exe file is located + "\")
// Obtain the path of the executable file that started the application, excluding the name of the executable file.
String str = System. Windows. Forms. Application. StartupPath;
Result: X: \ xxx (directory of the .exe file)
// Obtain the path of the executable file that started the application, including the name of the executable file.
String str = System. Windows. Forms. Application. ExecutablePath;
Result: X: \ xxx \ xxx.exe (.exefile directory. .exe file name)
// Obtain the current working directory of the application (unreliable ).
String str = System. IO. Directory. GetCurrentDirectory ();
Result: X: \ xxx (directory of the .exe file)
// Obtain the complete path of the current process, including the file name (process name ).
String str = this. GetType (). Assembly. Location;
Result: X: \ xxx \ xxx.exe (.exefile directory. .exe file name)
// Obtain the complete path of the new Process component and associate it with the active Process, including the file name (Process name ).
String str = System. Diagnostics. Process. GetCurrentProcess (). MainModule. FileName;
Result: X: \ xxx \ xxx.exe (.exefile directory. .exe file name)
// Obtain and set the full path of the current directory (that is, the directory from which the process starts.
String str = System. Environment. CurrentDirectory;
Result: X: \ xxx (directory of the .exe file)
// Obtain the base Directory of the current application domain of the current Thread, which is used by the Assembly conflict resolution program to detect the assembly.
String str = System. AppDomain. CurrentDomain. BaseDirectory;
Result: X: \ xxx \ (directory where the .exe file is located + "\")
// Obtain and set the name of the directory containing the application.
String str = System. AppDomain. CurrentDomain. SetupInformation. ApplicationBase;
Result: X: \ xxx \ (directory where the .exe file is located + "\")
// Obtain the path of the executable file that started the application, excluding the name of the executable file.
String str = System. Windows. Forms. Application. StartupPath;
Result: X: \ xxx (directory of the .exe file)
// Obtain the path of the executable file that started the application, including the name of the executable file.
String str = System. Windows. Forms. Application. ExecutablePath;
Result: X: \ xxx \ xxx.exe (.exefile directory. .exe file name)
// Obtain the current working directory of the application (unreliable ).
String str = System. IO. Directory. GetCurrentDirectory ();
Result: X: \ xxx (directory of the .exe file)
. NET three methods to get the current path code
// Web programming
HttpContext. Current. Server. MapPath ("FileName ")
System. Web. HttpContext. Current. Request. Path
// Windows Programming
System. Environment. CurrentDirectory
// Mobile Programming
Path. GetDirectoryName (System. Reflection. Assembly. GetExecutingAssembly (). GetName (). CodeBase );
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!