Reputation: 6427
if I want to get executable location what is the different between this command:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Directory.GetCurrentDirectory();
System.Environment.CurrentDirectory;
is there any different ? is its pointed to different location ?
Upvotes: 5
Views: 372
Reputation: 1038710
Assembly.GetExecutingAssembly().Location
Gets the location of the executing assembly. In an ASP.NET application this could vary due to shadow copying assemblies in system folders. The location of the currently executing assembly could be different than the location of the hosting process.
Directory.GetCurrentDirectory();
Gets the current working directory of the hosting process. In most cases this will be the directory where the executable is located but this working directory could be modified programatically using the SetCurrentDirectory method.
System.Environment.CurrentDirectory;
The directory from which the hosting process was started.
In a desktop application where you have everything in the same folder the 3 might return the same.
Upvotes: 5
Reputation: 22235
The current directory is the working directory, it's not necessarily the same as the directory that contains your assembly.
For example, if you were on the command line, in the root C:\ drive and did the command "SomeFolder\MyProgram.exe" the current directory would still be C:\
Upvotes: 2
Reputation: 62248
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
returns a folder of specified assembly.
Directory.GetCurrentDirectory()
gets the system current directory without backslash, according to MSDN. Directory.GetCurrentDirectory()
System.Environment.CurrentDirectory
gets or sets system current directory.
Upvotes: 2