This article introduces how to use C # To obtain the DLL and program path, and C # To obtain the path of a desktop, favorites, and other special systems. If you need to solve this problem, you can check it out.
Desktop path: Environment. GetFolderPath (Environment. SpecialFolder. Exclude topdirectory );
// Obtain the DLL Directory
Assembly myAssembly = Assembly. GetEntryAssembly ();
String path = myAssembly. Location;
DirectoryInfo dr = new DirectoryInfo (path );
Path = dr. Parent; // The upper-level directory of the current directory
C # How to obtain the current path of a program
System. Environment. CurrentDirectory;
// Example: c: test
Application. ExecutablePath; (including name)
// Example: c: testmyapp.exe
Application. StartupPath; (excluding the name)
// Example: c: test
// 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: xxxxxxxxx.exe (.exefile)
// 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: xxxxxx (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: xxxxxx (the 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: xxxxxx (the 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: xxxxxx (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: xxxxxxxxx.exe (.exefile)
// Obtain the current working directory of the application (unreliable ).
String str = System. IO. Directory. GetCurrentDirectory ();
Result: X: xxxxxx (directory of the .exe file)
Obtain the path of a special system folder (favorites, desktop)
1. favorites path
System. Environment. GetFolderPath (System. Environment. SpecialFolder. Favorites)
2. Desktop path
System. Environment. GetFolderPath (System. Environment. SpecialFolder. Desktop)
For more information, see enumeration classes.
System. Environment. SpecialFolder
Url: http://www.hzhuti.com/HTC/G14/