Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to dinamically define OpenFileDialog.InitialDirectory path?

Status
Not open for further replies.

pmhs

Programmer
Jun 23, 2002
12
PT
Greetings everyone.

I'm developing a desktop app and I'm trying to show the user an
OpenFileDialog so he/she can open a file of a certain type.
Now I would like to define the initial directory of the OpenFileDialog but
the problem is that the location of the files may vary from user to user.
I mean, I could simply define this:

dlgOpenFile.InitialDirectory = "c://Program Files/someProgram";

But that would not work if some user has his files in C:/someProgram, or
even if his drive's name isn't C:/, right?
So, I need to find out the path to <driveName>:/.../someProgram inside my
program.
I believe this is quite simple, but I'm not getting there.
Can anybody help me?
I would be very grateful...
TIA

sekhmet
 
If you are looking for the path of your executable then you may use:

Path.GetDirectoryName(Application.ExecutablePath);

Clarify if I misunderstood.. you are looking for the location of the running executable?

Regards,
John
 
Not exactly...
What I mean is I'm building a program to read and edit a file that is created by another application.
For example, let's say I'm building a program that edits a Microsoft Access database's properties (far from that).
When I show the OpenFileDialog I want the initial directory to be the directory where Microsoft Access is installed, wheter it is installed on C:/Program Files/Microsoft Access or C:/Access or whatever directory.
Is this possible? I think so, but I can't seem to figure it out...

sekhmet
 
1) you could look somewhere less dynamic to find the location. ie, when the other application creates the file, it could make a record, of where the file is, in a known place.

- or -

2) you could search for it - lengthy, slow, useless. don't do this.

____________________________________________________
If you like a post, show you care by giving it a star.
 
Hummmm...
Sorry Seanbo, but I didn't quite get it... :S
Sorry, but could you be more specific?
 
you writing an application to read a file made by another application. what application made the file? is it one you can manipulate? if so, you could make it store a record of files created in a pre-defined place.

____________________________________________________
If you like a post, show you care by giving it a star.
 
No. I can't manipulate the application that creates the file I want to edit.
I just know the directory in which the file is created:

<drive:\>somewhere-in-the-hard-drive\program-folder\user data
besides this I have no other information for sure...

sekhmet
 
try looking at this:

System.Environment.SpecialFolder.ProgramFiles

- i've not used it, but i think it should work; it looks promising

____________________________________________________
If you like a post, show you care by giving it a star.
 
Nope.
I've tried it and it returns an empty value...
:(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top