C # methods to get Project program paths
Gets the full path of the current process, including the filename (process name).
String str = this. GetType (). Assembly.location;
Result:x:\xxx\xxx\xxx.exe (. exe file directory +.exe file name)
Gets the full path of the main module that is associated with the currently active process, including the filename (process name), for the new process component.
String str = System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename;
Result:x:\xxx\xxx\xxx.exe (. exe file directory +.exe file name)
Gets and sets the fully qualified path to the current directory, which is the directory from which the process starts.
string str = System.Environment.CurrentDirectory;
Result:x:\xxx\xxx (the directory where the. exe file is located)
Gets the base directory of the current application domain for the current Thread, which is used by the Assembly resolver to probe the assembly.
string str = System.AppDomain.CurrentDomain.BaseDirectory;
Result:x:\xxx\xxx\ (the directory where the. exe file is located + "\")
Gets and sets the name of the directory that contains the application.
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
Result:x:\xxx\xxx\ (the directory where the. exe file is located + "\")
Gets 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\xxx (the directory where the. exe file is located)
Gets the path to the executable that started the application, including the name of the executable file.
string str = System.Windows.Forms.Application.ExecutablePath;
Result:x:\xxx\xxx\xxx.exe (. exe file directory +.exe file name)
Gets the current working directory of the application (unreliable).
String str = System.IO.Directory.GetCurrentDirectory ();
Result:x:\xxx\xxx (the directory where the. exe file is located)
1. System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename
Gets the full path of the module.
2. System.Environment.CurrentDirectory
Gets and sets the fully qualified directory of the current directory (the directory from which the process starts).
3. System.IO.Directory.GetCurrentDirectory ()
Gets the current working directory of the application. This is not necessarily the directory from which the program starts, it is possible that the program is placed in the C:\www, this function may return C:\Documents and settings\zyb\, or C:\Program files\adobe\, sometimes not necessarily return something, I don't get it either. (Note: This method value is not fixed, with the OpenFileDialog, SaveFileDialog and other objects determined by the directory changes)
4. System.AppDomain.CurrentDomain.BaseDirectory
Gets the base directory of the program.
5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
Gets and sets the name of the directory that contains the application.
6. System.Windows.Forms.Application.StartupPath
Gets the path of the executable file that started the application. The effect is the same as 2, 5. Just 5 more "\" behind the string returned.
7. System.Windows.Forms.Application.ExecutablePath
Gets the path and file name of the executable file that started the application, with the same effect as 1.
WebForm uses "Request.physicalapplicationpath to obtain the physical path of the virtual directory where the site resides, and finally contains" \ ";
2.c# WinForm with
A: "Application.startuppath": Gets the path to the directory where the current application resides, and finally does not contain "\";
B: "Application.executablepath": Gets the path to the current application file, including the name of the file;
C: "AppDomain.CurrentDomain.BaseDirectory": Gets the path to the directory where the current application resides, and finally contains "\";
D: "System.Threading.Thread.GetDomain (). BaseDirectory ": Gets the path to the directory where the current application resides, and finally contains" \ ";
E: "Environment.currentdirectory": Gets the current application path, and finally does not contain "\";
F: "System.IO.Directory.GetCurrentDirectory": Gets the current application path, and finally does not contain "\";
3.c# Windows service with "AppDomain.CurrentDomain.BaseDirectory" or "System.Threading.Thread.GetDomain (). BaseDirectory ";
Using "Environment.currentdirectory" and "System.IO.Directory.GetCurrentDirectory" will get the path of "system32" directory;
If you want to use "Application.startuppath" or "Application.executablepath", you need to manually add a reference to "System.Windows.Forms.dll" and at the beginning of the program with the "using System.Windows.Forms "declares the reference;
4. In the uninstall program to obtain the system installed directory:
System.Reflection.Assembly Curpath = System.Reflection.Assembly.GetExecutingAssembly ();
String path=curpath.location;//gets the path to the Installer class Setuplibrary file, obtains the directory where the file path is located;