C # obtain the DLL and program path. C # obtain the path of the desktop, favorites, and other special systems.

Source: Internet
Author: User
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 # obtainProgramCurrent Path Method

System. environment. currentdirectory;
// Example: C: \ test
Application. executablepath; (including name)
// Example: C: \ test \ myapp.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: \ 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 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://greatverve.cnblogs.com/archive/2012/03/21/Environment-path.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.