File open dialog... select folder only

  • Thread starter Thread starter MC D
  • Start date Start date
M

MC D

What's the best way to have a modal dialog that will only allow the
selection of a FOLDER, rather than a file? Is there a property of the
openFileDialog I'm missing, or is there another control altogether? I was
thinking of doing it from a treeView, but It seems like there ought to be a
control for this sort of thing!

-D
 
What's the best way to have a modal dialog that will only allow the
selection of a FOLDER, rather than a file? Is there a property of the
openFileDialog I'm missing, or is there another control altogether? I was
thinking of doing it from a treeView, but It seems like there ought to be a
control for this sort of thing!

-D

If your using VS.NET 2003 then, you can use the
System.Windows.Forms.FolderBrowserDialog...
 
It depends on which version of VS.NET (and VB.NET) you are using. If you are
using 2003 then you are in luck. VB.NET in 2003 has a BrowseForFolder Dialog
control that you can use. Otherwise, you will have to use the
SHBrowseForFolder API.
Go to this link:
http://msdn.microsoft.com/vbasic/downloads/samples/default.aspx

Scroll down about half way and you will see a selection to download a code
sample for VB.NET 2002 and Framework 1.0 that will give you what you need.
james
 
* "MC D said:
What's the best way to have a modal dialog that will only allow the
selection of a FOLDER, rather than a file? Is there a property of the
openFileDialog I'm missing, or is there another control altogether? I was
thinking of doing it from a treeView, but It seems like there ought to be a
control for this sort of thing!

NET 1.1:

'System.Windows.Forms.FolderBrowserDialog'

Note that there is a bug in Fx 1.1 that causes a really bad error when using
a path which is longer than ~128 characters. This occurs on unicode systems
only. Use the PInvoke solutions mentioned below instead.

The property for hiding the button that allows the user to create a new
folder doesn't work on Windows 2000.

..NET 1.0:

<http://www.codeproject.com/cs/miscctrl/folderbrowser.asp>
<http://support.microsoft.com/?kbid=306285>
<http://www.gotdotnet.com/team/vb/FolderBrowser.exe>
<http://groups.google.com/groups?selm=q0JKzDbmCHA.2144@cpmsftngxa09>
 
MC D said:
What's the best way to have a modal dialog that will only allow the
selection of a FOLDER, rather than a file? Is there a property of the
openFileDialog I'm missing, or is there another control altogether? I was
thinking of doing it from a treeView, but It seems like there ought to be a
control for this sort of thing!

-D

A twist on MC D's question.

Case one:
User is going to choose one file then OpenFileDialog works fine.

Case two:
User is going to choose more than one file, then OpenFileDialog works
fine, with a but:

I would like to save the user some clicking & scrolling, so if they
are going to choose all the files in a folder, then I would like to
give them the option of choosing the folder, but OpenFileDialog will
not work

Of course I could put 2 different buttons on my form
Button1 using FileOpen, if one file (or more than one but not all
files in folder)
Button2 using FolderBorwse in case user is going to choose all files

But the point is to simplify interface not to add more buttons...etc.

Is this possible?
 
Back
Top