C # WinForm methods to get the current path of executing programs

Source: Internet
Author: User

Go, original address: http://blog.csdn.net/yanlele424/article/details/7329389

1. Gets and sets the fully qualified path to the current directory.

string str = System.Environment.CurrentDirectory;

result:c:xxxxxx

2. Gets the path to the executable file that launched the application, not including the name of the executable file.

string str = System.Windows.Forms.Application.StartupPath;

Result:c:xxxxxx

3. Gets the full path of the new process component and associates it with the main module associated with the currently active process, including the file name.

String str = System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename;

Result:c:xxxxxxxxx.exe

4. Gets the base directory of the current application domain for Thread, which is used by the Assembly resolver to probe assemblies.

string str = System.AppDomain.CurrentDomain.BaseDirectory;

Result:c:xxxxxx

5. Get the current working directory of the application.

String str = System.IO.Directory.GetCurrentDirectory ();

Result:c:xxxxxx

6. Gets and sets the name of the directory that contains the application.

string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

Result:c:xxxxxx

7. Gets the full path of the current process, including the file name.

String str = this. GetType (). Assembly.location;

Result:c:xxxxxxxxx.exe

8. Get the path to the executable file that launched the application, including the name of the executable file.

string str = System.Windows.Forms.Application.ExecutablePath;

Result:c:xxxxxxxxx.exe


---------------------------------------------------------------------------------

In a DLL, it is sometimes necessary to use the resources in the main invoker, which will correctly obtain information such as the name of the calling program and its path. This needs to be distinguished from the name and path of the calling DLL itself!

This involves the use of the System.Reflection.Assembly assembly class.

getexecutingassembly : Gets the assembly that contains the code that is currently executing

getcallingassembly : Returns the System.Reflection.Assembly of the method that invokes the currently executing method

C # WinForm methods to get the current path of executing programs

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.