Javatpoint Logo
Javatpoint Logo

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.

VB.NET OpenFile Dialog Box

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.

Properties Description
CheckFileExists 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.
SafeFileName 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.
ShowReadOnly 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.
ReadOnlyChecked The ReadOnlyChecked property is used to obtain or set a value that validates whether the read-only checkbox is selected in the OpenFileDialog box.
ShowHelp The ShowHelp property is used to set a value that represents whether the Help button should be displayed in the dialog box.
Multiselect The MultiSelect property is used to set a value that allows the user to select multiple files from the OpenFileDialog box.
AddExtension 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.
DefaultExt The DefaultExt property is used to set or get the default extension of a file.
FileName The FileName property represents the selected file name as a string in the file dialog box.
Filter 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

Method Description
OpenFile() 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.
Reset() 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.

OpenDialog.vb

Output:

VB.NET OpenFile Dialog Box

Now, click on the Click Me button, it opens the OpenDialog box to select an image, as shown below.

VB.NET OpenFile Dialog Box

After selecting the image, click the Open button to display the selected image in Windows Form, as shown below.

VB.NET OpenFile Dialog Box





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA