468,463 Members | 2,121 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

File open dialog... select folder only

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
Nov 20 '05 #1
4 11844
On 2004-02-08, MC D <no****@earthtalk.com> wrote:
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...

--
Tom Shelton [MVP]
Powered By Gentoo Linux 1.4
Loose bits sink chips.
Nov 20 '05 #2
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/dow...s/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" <no****@earthtalk.com> wrote in message
news:10*************@corp.supernews.com...
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

Nov 20 '05 #3
* "MC D" <no****@earthtalk.com> scripsit:
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%40cpmsftngxa09>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
"MC D" <no****@earthtalk.com> wrote in message news:<10*************@corp.supernews.com>...
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?
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Alok Joshi | last post: by
2 posts views Thread by Lonnie | last post: by
5 posts views Thread by Krishna | last post: by
3 posts views Thread by JoNaS | last post: by
5 posts views Thread by charles | last post: by
1 post views Thread by jhaek19 | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.