Solved

Getting the Calling Directory of an .exe

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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