VB.NET OpenFile Dialog Box
It is used to display the OpenFileDialog box that allows the user to select and open a file. It also facilitates the user to select multiples files from the dialog box. However, the OpenFileDialog box contains a list of files and folders from which the user can choose the required files to process the form.
Let's create an OpenFileDialog control in the VB.NET Windows form by using the following steps.
Step 1: Drag the OpenFileDialog control from the toolbox and drop it to the Windows form, as shown below.
Step 2: Once the OpenFileDialog is added to the form, we can set various properties of the OpenFileDialog by clicking on the OpenFileDialog.
OpenFile Dialog Properties
There are following properties of the OpenFileDialog Box in the VB.NET.
||The CheckFileExists property is used to get or set a value that confirms whether the dialog box displays a warning message when the particular file does not exist.
||The property is used to get the specific file name and extension for the selected file in the dialog box. However, it does not include the file path for the file name.
||The ShowReadOnly property is used to obtain or set a value that confirms whether the dialog box provides only the read checkbox to read the file.
||The ReadOnlyChecked property is used to obtain or set a value that validates whether the read-only checkbox is selected in the OpenFileDialog box.
||The ShowHelp property is used to set a value that represents whether the Help button should be displayed in the dialog box.
||The MultiSelect property is used to set a value that allows the user to select multiple files from the OpenFileDialog box.
||The AddExtension property is used to set a value that validates whether the dialog box automatically adds an extension to a file if the user forgets to add the extension.
||The DefaultExt property is used to set or get the default extension of a file.
||The FileName property represents the selected file name as a string in the file dialog box.
||It is an important property of the OpenFileDialog box, which is used to filter the files. It is also used to display files in a dialog box by specifying a file type. For example, we have to set "Text|*.txt" in a filter to display only text files in the dialog box.
Methods of OpenFile Dialog Control
||The OpenFile method is used to open the selected file by the user with reading only permission. The selected file is specified by the FileName property of the dialog box.
||The Reset() method is used to reset all changes to their default values.
Let's create a simple program to display the OpenFileDialog box in the VB.NET Windows Forms.
Now, click on the Click Me button, it opens the OpenDialog box to select an image, as shown below.
After selecting the image, click the Open button to display the selected image in Windows Form, as shown below.