Get Folder

  • Thread starter Thread starter Doug Bell
  • Start date Start date
D

Doug Bell

Hi,
Is there a way to use the OpenFileDialog to retrieve a directory?

I need to allow the user to set a directory and it may not have any files in
it.

Doug
 
Doug Bell said:
Is there a way to use the OpenFileDialog to retrieve a directory?

Hi Doug,

if the directory is empty, no.
I need to allow the user to set a directory and it may not have any files
in
it.

Another possibility is to use the FolderBrowserDialog and to check whether
the selected directory contains files or not:

If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
Dim di As DirectoryInfo = New DirectoryInfo( _
FolderBrowserDialog1.SelectedPath)
If di.GetFiles.Length > 0 Then
MessageBox.Show("...")
End If
End If

Cheers

Arne Janning
 
* "Doug Bell said:
Is there a way to use the OpenFileDialog to retrieve a directory?

..NET 1.1:

'FolderBrowserDialog' Class ('System.Windows.Forms.FolderBrowserDialog')
<URL:http://msdn.microsoft.com/library/e...WindowsFormsFolderBrowserDialogClassTopic.asp>

Note that there is a bug in the .NET Framework 1.1 that causes a really bad
error when using a path longer than about 128 characters. This occurs on
Unicode systems only. Use the p/invoke solutions listed below instead.

..NET 1.0:

Folder Browser component for .NET
<URL:http://www.codeproject.com/cs/miscctrl/folderbrowser.asp>

HOW TO: Implement a Managed Component that Wraps the Browse For Folder
Common Dialog Box by Using Microsoft Visual Basic .NET
<URL:http://support.microsoft.com/?kbid=811004>

FolderBrowser.msi
<URL:http://www.gotdotnet.com/team/vb/FolderBrowser.exe>

How to pick a directory
<URL:http://groups.google.com/groups?selm=q0JKzDbmCHA.2144@cpmsftngxa09>
 
I was writing this already that this message would come, however to be sure
I waited (The word terrrible is disapeared, some reason)

:-)

Cor
 

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

Back
Top