Difference in getting the current exe directory

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
 
F

Family Tree Mike

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.
 
M

Mathew Coleman

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top