468,140 Members | 1,462 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

FolderBrowserDialog doesn't initialize

I'm trying to have the user browse to a folder, once they click a
button, using the standard FolderBrowserDialog tool,
System.Windows.Forms.FolderBrowserDialog. I'm using VB.Net 2005.
There is a property, SelectedPath, that you're supposed to be able to
set that will initialize the folder browser window so that the tree
structure is already opened at that folder. The problem is that it
doesn't seem to work. No matter what I put, it has all the folders
and drives collapsed. It doesn't start off with the one I want open.
Anyone else experience this?

The help says:
"If the SelectedPath property is set before showing the dialog box,
the folder with this path will be the selected folder, as long as
SelectedPath is set to an absolute path that is a subfolder of
RootFolder (or more accurately, points to a subfolder of the shell
namespace represented by RootFolder)."

I want them to be able to pick any folder on their computer, and not
be limited to just those folders in a certain folder, like My
Documents, so I set RootFolder = Environment.SpecialFolder.MyComputer.
Regards,
ImageAnalyst
' Root folder has to be one of the special folders.
Me.FolderBrowserDialog1.RootFolder =
Environment.SpecialFolder.MyComputer

' Determine which folder they're about to start browsing
from.
' Doesn't work!
FolderBrowserDialog1.SelectedPath = "C:\Program Files"
' Show the FolderBrowserDialog opened at above folder
(doesn't work).
Dim result As DialogResult =
FolderBrowserDialog1.ShowDialog()

Mar 11 '07 #1
3 6434
Well maybe it is sort of picking it - I just couldn't see it because
of the low contrast on my notebook computer. But it only highlights
the folder and doesn't have it expanded to show all the subfolders.
Anyone know how to get it to expand the selected path? Like in my
example below, have Program Files folder be selected and expanded so
that all the subfolders of Program Files are shown and the user
doesn't have to double click to get it to expand. (I'd just like to
save them a step if possible).
Regards,
ImageAnalyst

On Mar 11, 3:09 pm, "ImageAnalyst" <imageanal...@mailinator.com>
wrote:
I'm trying to have the user browse to a folder, once they click a
button, using the standard FolderBrowserDialog tool,
System.Windows.Forms.FolderBrowserDialog. I'm using VB.Net 2005.
There is a property, SelectedPath, that you're supposed to be able to
set that will initialize the folder browser window so that the tree
structure is already opened at that folder. The problem is that it
doesn't seem to work. No matter what I put, it has all the folders
and drives collapsed. It doesn't start off with the one I want open.
Anyone else experience this?

The help says:
"If the SelectedPath property is set before showing the dialog box,
the folder with this path will be the selected folder, as long as
SelectedPath is set to an absolute path that is a subfolder of
RootFolder (or more accurately, points to a subfolder of the shell
namespace represented by RootFolder)."

I want them to be able to pick any folder on their computer, and not
be limited to just those folders in a certain folder, like My
Documents, so I set RootFolder = Environment.SpecialFolder.MyComputer.
Regards,
ImageAnalyst

' Root folder has to be one of the special folders.
Me.FolderBrowserDialog1.RootFolder =
Environment.SpecialFolder.MyComputer

' Determine which folder they're about to start browsing
from.
' Doesn't work!
FolderBrowserDialog1.SelectedPath = "C:\Program Files"
' Show the FolderBrowserDialog opened at above folder
(doesn't work).
Dim result As DialogResult =
FolderBrowserDialog1.ShowDialog()

Mar 11 '07 #2
ImageAnalyst wrote:
I'm trying to have the user browse to a folder, once they click a
button, using the standard FolderBrowserDialog tool,
You must understand that "SelectedPath" means just that - Selected. It
doesn't mean - OpenThePath or ExpandThePath.

The quickest way I could think of to achieve your required result is as
follows (watch for wrapping) -

With FolderBrowserDialog1
Dim sString() As String =
System.IO.Directory.GetDirectories("C:\Program Files", "*.",
SearchOption.TopDirectoryOnly)
.SelectedPath = sString(0)
Dim result As DialogResult = .ShowDialog
End With

Obviously you'd need to add Error Handling etc., but this should get you
started. Hopefully someone else will know of a better way.
ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
Mar 11 '07 #3
ShaneO:
Sorry for the late thanks. I did use your workaround (regarding
opening a subfolder) and it works fine.
Thanks,
ImageAnalyst

On Mar 11, 7:07 pm, ShaneO <spc...@optusnet.com.auwrote:
ImageAnalystwrote:
I'm trying to have the user browse to a folder, once they click a
button, using the standard FolderBrowserDialog tool,

You must understand that "SelectedPath" means just that - Selected. It
doesn't mean - OpenThePath or ExpandThePath.

The quickest way I could think of to achieve your required result is as
follows (watch for wrapping) -

With FolderBrowserDialog1
Dim sString() As String =
System.IO.Directory.GetDirectories("C:\Program Files", "*.",
SearchOption.TopDirectoryOnly)
.SelectedPath = sString(0)
Dim result As DialogResult = .ShowDialog
End With

Obviously you'd need to add Error Handling etc., but this should get you
started. Hopefully someone else will know of a better way.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.

Apr 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by hhh12347 | last post: by
6 posts views Thread by John Krueger | last post: by
4 posts views Thread by hotmit | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.