Search Results:

Friday, September 25, 2009

Get Open Dialog to browse system files

The OpenFileDialog class is defined in Windows.Forms class. You need to add to reference to System.Windows.Form.dll library and call using System.Windows.Forms before using the class.

The OpenFileDialog class can be used to open a file similar to CFileDialog 's Open method in VC++. This class is derived from FileDialog. OpenFile method of this class opens a file which can be read by a steam.

In this sample code, I have use OpenFileDialog class to browse a file.

Private fdlg As OpenFileDialog = New OpenFileDialog()
Private fdlg.Title = "C# Corner Open File Dialog"
Private fdlg.InitialDirectory = "c:\"
Private fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
Private fdlg.FilterIndex = 2
Private fdlg.RestoreDirectory = True
If fdlg.ShowDialog() = DialogResult.OK Then
textBox1.Text = fdlg.FileName
End If

Title member let you set the title of the open dialog. Filter member let you set a filter for types of files to open.

No comments:

Post a Comment