Question Get directory of application exe

Cheetah

Well-known member
Joined
Oct 12, 2006
Messages
232
Programming Experience
Beginner
I always thought that System.IO.Directory.GetCurrentDirectory() got the directory that the main executable of your application was in, but it would appear that I am wrong and this gets the directory that the application was started from, so if it was started in the start menu, it would get the start menu directory.

So how do you get the directory that the application exe is in?

Thanks.
 
CurrentDirectory is a system-wide environment variable, it reflects the operating systems current directory and any application may change this at any time. Try Application.StartupPath.
 
Thanks - that gets what I wanted.

I am creating a user control (from a control library) and i want the user control to have the string returned from Application.StartupPath. I'm guessing I will have to pass it the string somehow when it loads? Or is there anyway it can get it from the parent form or something like that?
 
Why can't you use Application.StartupPath? Or did I misunderstand?
 
I can use Application.StartupPath to get what I want.

But I am creating a Control Library and from the control library I want to be able to get the Application.StartupPath of the application the control library is used in as intellisense doesn't allow me to get Application.StartupPath from the control library.

Hope that makes sense.
 
Try these suggestions: http://www.vbdotnetforums.com/showthread.php?t=13822

What I don't understand is that you say UserControl which is a class in Forms namespace, so you then have Forms library referenced and I also thought you had the namespace imported then. How about trying to qualify it?
System.Windows.Forms.Application.StartupPath
 
What I don't understand is that you say UserControl which is a class in Forms namespace, so you then have Forms library referenced and I also thought you had the namespace imported then. How about trying to qualify it?

That works! (System.Windows.Forms.Application.StartupPath).

LOL - I see the issue now, I stupidly named one of my properties for the user control "Application", so intellisense used that :s

Thanks for your help.
 
Back
Top