Solved

Getting the Calling Directory of an .exe

Posted on 2003-10-31
5
426 Views
Last Modified: 2010-04-16
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
Comment
Question by:jjacksn
5 Comments
 
LVL 5

Author Comment

by:jjacksn
ID: 9661499
I mean System.IO.Directory.GetCurrentDiretory()
0
 
LVL 2

Expert Comment

by:smitty22
ID: 9661544
> 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
 
LVL 19

Expert Comment

by:Desp
ID: 9662193
Application.ExecutablePath

this will return what you want

0
 

Expert Comment

by:harbran
ID: 9662213

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
 
LVL 19

Accepted Solution

by:
Desp earned 250 total points
ID: 9663302
Application.StartupPath will also return the app path
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now