Link to home
Start Free TrialLog in
Avatar of jjacksn
jjacksn

asked on

Getting the Calling Directory of an .exe

I am trying to use System.IO.Directory.GetCallingDirectory() to get the directory of my executable.  Its returning a directory of not my executable.  So I have two quetsions:

1.  Is there a better way to determine the Calling Directory of the exe, or should I just make this call in the main constructor and save the value.

2.  What / When / Why does this change from the actual CallingDirectory() of the exe
Avatar of jjacksn
jjacksn

ASKER

I mean System.IO.Directory.GetCurrentDiretory()
> should I just make this call in the main constructor and save the value.
1)  Yes

2) GetCurrentDirectory returns the current working directory, not the originating directory of the application. So your application must somehow be changing the working directory before you are calling GetCurrentDirectory.
Application.ExecutablePath

this will return what you want


What I use is:
String path =  Path.GetDirectoryName( Assembly.GetEntryAssembly().Location ) + Path.DirectorySeparatorChar
My exes always reside in <AppFolder>\Bin\, therefore I remove the last Folder and keep this path in a SetUpHandler module at hand.
The Path object is in System.IO

ASKER CERTIFIED SOLUTION
Avatar of Fahad Mukhtar
Fahad Mukhtar
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial