use the openfiledialog to folder level
Using the code i have below (allows you to select files), how can I just select a folder? Thanks!
Dim FileDlg as new OpenFileDialog()
openfildlg.filter = "All files (*.*)|*.*"
openfiledlg.restoredirectory = true
if openfiledlg.showdialog() = dialogresult.OK then
lblfile.text = Openfiledlg.filename
end if
Yes, the previously posted code only works with VS2005 / .NET 2.0. Please see if the following modifications works for you:
Dim dialog As New FolderBrowserDialog()
If dialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim folder As String = dialog.SelectedPath
' Process folder here...
End If
dialog.Dispose()Then again... it might not work after all. Looks like FolderBrowserDialog was introduced in VS2003 / .NET 1.1...
Andrej
No there is no method called FolderBrowserDialog().
I have been doing some searching and a guys said this worked for him:
Dim oFolder As Shell32.Folder
Dim oShell As Shell32.Shell = New Shell32.Shell()
oFolder = oShell.BrowseForFolder(0, "Select a Folder:", 0, "C:\")
how would I import a way to use the Shell32 objects?
That looks like a good solution. I looked at it and it seemed too confusing for me though. I found one solution that did work for me. You have to add the System.Design reference and use the class below.
Call the class by saying: lblfilename.text = Browsefolderdialog.showdialog("Select directory")
I appreciate your help!
Class is listed below:
'if any suggestion please send mail to thulasi.sekaran@gmail.com
Public Class ClassBrowseFolder
Inherits System.Windows.Forms.Design.FolderNameEditor ' Reference System.Design.Dll
Dim MyBrowseFolder As New FolderBrowser()
Public Function ShowDialog(ByVal browseFolderTitle As String)
With MyBrowseFolder
.Style = FolderBrowserStyles.BrowseForComputer
'.Style = FolderBrowserStyles.BrowseForEverything
'.Style = FolderBrowserStyles.BrowseForPrinter
'.Style = FolderBrowserStyles.RestrictToDomain
'.Style = FolderBrowserStyles.RestrictToFilesystem
'.Style = FolderBrowserStyles.RestrictToSubfolders
'.Style = FolderBrowserStyles.ShowTextBox
.StartLocation = FolderBrowserFolder.MyDocuments
'.StartLocation = FolderBrowserFolder.Desktop
'.StartLocation = FolderBrowserFolder.Favorites
'.StartLocation = FolderBrowserFolder.MyComputer
'.StartLocation = FolderBrowserFolder.MyPictures
'.StartLocation = FolderBrowserFolder.NetAndDialUpConnections
'.StartLocation = FolderBrowserFolder.NetworkNeighborhood
'.StartLocation = FolderBrowserFolder.Printers
'.StartLocation = FolderBrowserFolder.Recent
'.StartLocation = FolderBrowserFolder.SendTo
'.StartLocation = FolderBrowserFolder.StartMenu
'.StartLocation = FolderBrowserFolder.Templates
.Description = browseFolderTitle ' For Dialog box title
.ShowDialog()
ShowDialog = .DirectoryPath ' Return the Folder path
End With
End Function
End Class