Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different between executable location

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 ?

like image 852
MoShe Avatar asked Oct 17 '11 14:10

MoShe


2 Answers

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.

like image 133
Darin Dimitrov Avatar answered Sep 26 '22 17:09

Darin Dimitrov


  1. Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) returns a folder of specified assembly.

  2. Directory.GetCurrentDirectory() gets the system current directory without backslash, according to MSDN. Directory.GetCurrentDirectory()

  3. System.Environment.CurrentDirectory gets or sets system current directory.

like image 40
Tigran Avatar answered Sep 24 '22 17:09

Tigran