Solved

Getting the Calling Directory of an .exe

Posted on 2003-10-31
5
427 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

24 Experts available now in Live!

Get 1:1 Help Now