Select folder using OpenFileDialog control

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)

This entry was posted in .Net, WPF. Bookmark the permalink.

6 Responses to Select folder using OpenFileDialog control

  1. Dan says:

    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?

  2. anuraj says:

    Sorry Dan, I don’t think, you can’t do that. :(

  3. Pingback: Using OpenFileDialog to select a folder with WPF « Dan Schwartz

  4. Bini says:

    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

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>