Few days back one of my friend got a nice requirement from the client. The client want to select a Folder using the OpenFileDialog control. And after some googleing he got a solution, to select Folder using OpenFileDialog control.
Code to Select folder using OpenFileDialog control
Using _OpenFileDialog As New OpenFileDialog
With _OpenFileDialog
.CheckFileExists = False
.CheckPathExists = True
.Multiselect = False
.FileName = "(Get Folder)"
.Filter = "Folders only|*.FOLDER"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
MessageBox.Show(.FileName)
End If
End With
End Using
Note : In WPF we can’t use OpenFileDialog with using keyword. And to use OpenFileDialog in WPF you need to import a namespace(Microsoft.Win32)
I’ve got my dialog to only show folders, but when I click the “Open” button it just opens the folder. Is there a way to just have it return so I can get the folder they clicked?
Sorry Dan, I don’t think, you can’t do that.
Pingback: Using OpenFileDialog to select a folder with WPF « Dan Schwartz
Using dlgFodlerBrowser As New FolderBrowserDialog
dlgFodlerBrowser.Reset()
dlgFodlerBrowser.RootFolder = Environment.SpecialFolder.MyComputer
dlgFodlerBrowser.ShowNewFolderButton = True
dlgFodlerBrowser.Description = “Select Folder or Create New”
If dlgFodlerBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then
Me.TextBoxDirectory.Text = dlgFodlerBrowser.SelectedPath
End If
End Using
It is using OpenFileDialog, not using FolderBrowseDialog
doesnt work