Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

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
0
jjacksn
Asked:
jjacksn
1 Solution
 
jjacksnAuthor Commented:
I mean System.IO.Directory.GetCurrentDiretory()
0
 
smitty22Commented:
> 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.
0
 
Fahad MukhtarDistinguished EngineerCommented:
Application.ExecutablePath

this will return what you want

0
 
harbranCommented:

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

0
 
Fahad MukhtarDistinguished EngineerCommented:
Application.StartupPath will also return the app path
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now