OpenFileDialog in Visual Basic .NET

OpenFileDialog is one of the dialog control in VB.NET. You can use this control to open the file and get its filename
You can use filtering to show the files you want. There are several properties of the OpenFileDialog control which you can change according to your requirement

Now I am going to code the following user interface to open the FileDialog and get the name of the file you select to TextBox control

First you have to frag and drop the OpenFileDialog control from the ToolBox

This is the code for the Button Click handler

Code explanation

  • Line 5: Using OpenFileDialog1.Filter property to filter only the text file
  • Line 7: When you open the OpenFileDialog window you can check for OK button press with Windows.Forms.DialogResult.OK
  • Line 9: Get the file name to TextBoxFileName.Text

Leave a Reply

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