By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,772 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

dialog to choose folder in vb .net 2005

P: n/a
hello

how do i create a dialog to allow the user to choose a folder?

i tried FolderBrowserDialog but encountered a couple of problems:
- when you specify the starting location (property RootFolder) you have
to supply a constant such as MyComputer, you're not allowed to supply a
literal value such as "C:\path\to\whatever".
- once you specify the RootFolder, the user isn't allowed to navigate
any higher than that in the directory tree.

class OpenFileDialog behaves as i need, except that it forces the user
to specify a file, and i want to prompt the user for a directory.
excel VBA supports Application.FileDialog(MsoFileDialogFolderPicker)
which is exactly what i need except that i can't find an equivalent in
VB .NET 2005.

any ideas?

many thanks
eric

Oct 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The best way to do that would be to use the Folder Browser Dialog. In your
post you say "once the user selects the root folder they can't navigate any
higher" or something of that sort. The root folder is the highest folder.
---------------
-Dylan Copeland
http://www.dc-studios.net
http://www.vbdotnetforum.com
"sp********@gmail.com" wrote:
hello

how do i create a dialog to allow the user to choose a folder?

i tried FolderBrowserDialog but encountered a couple of problems:
- when you specify the starting location (property RootFolder) you have
to supply a constant such as MyComputer, you're not allowed to supply a
literal value such as "C:\path\to\whatever".
- once you specify the RootFolder, the user isn't allowed to navigate
any higher than that in the directory tree.

class OpenFileDialog behaves as i need, except that it forces the user
to specify a file, and i want to prompt the user for a directory.
excel VBA supports Application.FileDialog(MsoFileDialogFolderPicker)
which is exactly what i need except that i can't find an equivalent in
VB .NET 2005.

any ideas?

many thanks
eric

Oct 13 '06 #2

P: n/a
<DylanCopel...@discussions.microsoft.comwrote:
The best way to do that would be to use the Folder Browser Dialog. In your
post you say "once the user selects the root folder they can't navigate any
higher" or something of that sort. The root folder is the highest folder.
i want to prompt the user to name a directory. suppose i know that the
user will usually choose "c:\foo", but that she will occasionally
choose "c:\bar".

i want to launch the dialog with it already pointing to "c:\foo" and
usually the user will click OK. but in those exceptional cases where
the the user wants c:\bar, she would navigate up to c: then down to
c:\foo.

this is a simplified example. in reality my default location would be
something like "c:\path\to\whatever" but the user must have the
possibility to select any folder anywhere.

so there are two problems with FolderBrowserDialog:
1) whatever I specify for RootFolder, the user can go no higher, so i
have to specify the highest possible location, i.e. MyComputer, even
though the user usally wants "c:\path\to\whatever".
2) RootFolder only accepts predefined constants like MyComputer so in
fact i can't set it to an arbitrary location like
"c:\path\to\whatever".

i want a dialog which will allow me to specify any location as the
default startup value, and will allow the user to navigate upward from
that location.

regards
eric

Oct 13 '06 #3

P: n/a
sp********@gmail.com wrote:
i want to launch the dialog with it already pointing to "c:\foo" and
usually the user will click OK. but in those exceptional cases where
the the user wants c:\bar, she would navigate up to c: then down to
c:\foo.
The RootFolder property isn't the one you want to use. As Dylan mentioned,
the root folder is the highest folder you allow the user to browse to, so
for example you might set this to "C:\Program Files" if you wanted to force
the user to select a folder below that.

Instead, you want to use the SelectedPath property. Don't set RootFolder at
all, but set SelectedPath to "C:\Foo" or wherever you want. The dialog will
initially open to that location, but will let the user navigate anywhere
they want to go. When they click OK, you can read the folder they selected
back from the same property.

HTH,

--

(O)enone
Oct 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.