Difference in getting the current exe directory

  • Thread starter Thread starter Kakkanattu
  • Start date Start date
K

Kakkanattu

Hi,
In desktop application, we use different ways to get the current
execution directory.
I. AppDomain.CurrentDomain.BaseDirectory
II. Environment.CurrentDirectory
III. Directory.GetCurrentDirectory()
IV. Assembly.GetExecutingAssembly().Location

Can u please help me to know the difference of all these? Also is
there any other way to get the current directory other than the above?

Thanks in advance
Robin Mathew
 
More often than not, only 2 and 3, which are equivalent, will get the current
directory.

1 "Gets the base directory that the assembly resolver uses to probe for
assemblies.", per MSDN.

4 gets the location of the assembly that is executing. When a shortcut to
an executable is used, the current directory may be different than the
executable location.

I suspect there are many other ways to get the current location.
 
AppDomain.BaseDirectory
Gets the base directory that the assembly resolver uses to probe for
assemblies and it is similar to AppDomainSetup.ApplicationBase.

Environment.CurrentDirectory
Gets or sets the fully qualified path of the current working directory.

Directory.GetCurrentDirectory()
Gets the current working directory of the application. Obviusly it is an
read only method.

Assembly.GetExecutingAssembly().Location
Gets the path or UNC location of the loaded file that contains the manifest.
 
Back
Top