dialog to choose folder in vb .net 2005

G

Guest

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
 
G

Guest

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.
 
G

Guest

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
 
O

Oenone

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,
 

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