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)
Image viewer in WPF – Part I (Selecting multiple files with FileOpen Dialog)
Last few days I am working in WPF project, it is nice and good. So I started searching for sample applications to learn WPF. Here is the one, an Image viewer. According to MSDN the image control in WPF supports *.bmp;*.gif;*.ico;*.jpg;*.png;*.wdp;*.tiff file formats. And I need to check how can we open multiple files using the File Open Dialog.
here is the code to open multiple files with File Open Dialog in WPF
Dim OpenFileDlg As New OpenFileDialog()
With OpenFileDlg
.CheckFileExists = True
.CheckPathExists = True
.Filter = "Supported Images|*.bmp;*.gif;*.ico;*.jpg;*.png;*.wdp;*.tiff"
.Multiselect = True 'Allow selection of multiple files
.ReadOnlyChecked = True
.ShowReadOnly = False
If .ShowDialog(Me) = True Then
For Each file As String In .FileNames
m_FilesUpdated.Add(New BitmapImage(New Uri(file))) 'Adding each file to the collection
Next
End If
End With
And the screen shot of the Image viewer running on my machine
