How to set OpenFileDialog to "My Computer"

S

Steve Marshall

Hi All,

Is it possible to set the InitialDirectory property of an
OpenFileDialog so it will open at the "My Computer" level? I want it
to open showing all the available drives. If so, what do I put in the
property? I've tried the obvious - "My Computer", but of course that
doesn't do it.

Thanks
 
T

Tim Patrick

The "My Computer" folder isn't a real directory, so you can't access it using
normal directory methods. In Visual Basic 2005, you can access all of the
drives through the My.Computer.FileSystem.Drives collection.
 
S

Steve Marshall

Thanks for that. I'm not sure I want or need to go to quite that
length, but I'll try to take it all in.
 
R

RobinS

You could try My.Computer.FileSystem.SpecialDirectories.Desktop. At least
from there, they can easily choose "My Computer".
Robin
 
S

Steve Marshall

Thanks Robin, but at the moment I'm a VS2003 user, and I think
My.Computer... is a VS2005 and/or Framework 2 feature.
 
A

Andrew Morton

Steve said:
Thanks Robin, but at the moment I'm a VS2003 user, and I think
My.Computer... is a VS2005 and/or Framework 2 feature.

Then you'll be after GetFolderPath(Environment.SpecialFolder.MyComputer).

HTH

Andrew
 
H

Herfried K. Wagner [MVP]

Andrew Morton said:
Then you'll be after GetFolderPath(Environment.SpecialFolder.MyComputer).

.... which won't be very useless because the path assigned to 'MyComputer' is
"".

What you can try instead (untested!):

\\\
Const STR_MYCOMPUTER_CLSID As String =
"{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
fbd.InitialDirectory = "::" & STR_MYCOMPUTER_CLSID
///
 
S

Steve Marshall

Works beautifully - many thanks Herfried, and all other respondents
too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top