This article summarizes. NET (including Asp.net/winform, etc.) to obtain the current path of the various methods, with a certain reference value, followed by a small series to see it together
The following summarizes the various ways that. NET (including Asp.net/winform, etc.) gets the current path
Gets the full path of the current process, including the file name (process name).
String str = this. GetType (). Assembly.location;
Result:x:\xxx\xxx\xxx.exe (. exe file in the same directory as +.exe filename)
Gets the full path of the new process component and its main module associated with the currently active process, including the file name (process name).
String str = System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename;
Result:x:\xxx\xxx\xxx.exe (. exe file in the same directory as +.exe filename)
Gets and sets the fully qualified path to the current directory (that is, the directory from which the process starts).
string str = System.Environment.CurrentDirectory;
Result:x:\xxx\xxx (the directory where the. exe file resides)
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: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 to the executable file that launched the application, not including the name of the executable file.
string str = System.Windows.Forms.Application.StartupPath;
Result:x:\xxx\xxx (the directory where the. exe file resides)
Gets 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:x:\xxx\xxx\xxx.exe (. exe file in the same directory as +.exe filename)
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 resides)
Gets the full path of the current process, including the file name (process name).
String str = this. GetType (). Assembly.location;
Result:x:\xxx\xxx\xxx.exe (. exe file in the same directory as +.exe filename)
Gets the full path of the new process component and its main module associated with the currently active process, including the file name (process name).
String str = System.Diagnostics.Process.GetCurrentProcess (). Mainmodule.filename;
Result:x:\xxx\xxx\xxx.exe (. exe file in the same directory as +.exe filename)
Gets and sets the fully qualified path to the current directory (that is, the directory from which the process starts).
string str = System.Environment.CurrentDirectory;
Result:x:\xxx\xxx (the directory where the. exe file resides)
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: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 to the executable file that launched the application, not including the name of the executable file.
string str = System.Windows.Forms.Application.StartupPath;
Result:x:\xxx\xxx (the directory where the. exe file resides)
Gets 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:x:\xxx\xxx\xxx.exe (. exe file in the same directory as +.exe filename)
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 resides)
. NET three ways to get the current path of 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);