What is OpenFile Dialog Box in VB.net?
The OpenFile Dialog box in VB.net has a list of files and folders from which the user can choose the files needed to process the form.
OpenFile Dialog Properties in VB.net
The Open File Dialog Box in VB.net has the following Properties:
# | Open File Dialog Properties in VB.net | Description |
---|---|---|
1. | AddExtension | Gets or sets a value indicating whether the dialog box automatically adds an extension to a file name if the user omits the extension. |
2. | AutoUpgradeEnabled | Gets or sets a value indicating whether this FileDialog instance should automatically upgrade appearance and behavior when running on Windows Vista. |
3. | CheckFileExists | Gets or sets a value indicating whether the dialog box displays a warning if the user specifies a file name that does not exist. |
4. | CheckPathExists | Gets or sets a value indicating whether the dialog box displays a warning if the user specifies a path that does not exist. |
5. | CustomPlaces | Gets the custom places collection for this FileDialog instance. |
6. | DefaultExt | Gets or sets the default file name extension. |
7. | DereferenceLinks | Gets or sets a value indicating whether the dialog box returns the location of the file referenced by the shortcut or whether it returns the location of the shortcut (.lnk). |
8. | FileName | Gets or sets a string containing the file name selected in the file dialog box. |
9. | FileNames | Gets the file names of all selected files in the dialog box. |
10. | Filter | Gets or sets the current file name filter string, which determines the choices that appear in the “Save as file type” or “Files of type” box in the dialog box. |
11. | FilterIndex | Gets or sets the index of the filter currently selected in the file dialog box. |
12. | InitialDirectory | Gets or sets the initial directory displayed by the file dialog box. |
13. | Multiselect | Gets or sets a value indicating whether the dialog box allows multiple files to be selected. |
14. | ReadOnlyChecked | Gets or sets a value indicating whether the read-only check box is selected. |
15. | RestoreDirectory | Gets or sets a value indicating whether the dialog box restores the current directory before closing. |
16. | SafeFileName | Gets the file name and extension for the file selected in the dialog box. The file name does not include the path. |
17. | SafeFileNames | Gets an array of file names and extensions for all the selected files in the dialog box. The file names do not include the path. |
18. | ShowHelp | Gets or sets a value indicating whether the Help button is displayed in the file dialog box. |
19. | ShowReadOnly | Gets or sets a value indicating whether the dialog box contains a read-only check box. |
20. | SupportMultiDottedExtensions | Gets or sets whether the dialog box supports displaying and saving files that have multiple file name extensions. |
21. | Title | Gets or sets the file dialog box title. |
22. | ValidateNames | Gets or sets a value indicating whether the dialog box accepts only valid Win32 file names. |
OpenFile Dialog Methods in VB.net
The Open File Dialog Box in VB.net has the following Methods:
# | Open File Dialog Methods in VB.net | Description |
---|---|---|
1. | 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. |
2. | Reset() | The Reset() method is used to reset all changes to their default values. |
Let’s make a simple program that uses VB.NET Windows Forms to show the OpenFileDialog Box.
Public Class Form1
Private Sub Button1_Click_3(sender As Object, e As EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog <> Windows.Forms.DialogResult.Cancel Then
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
End Sub
End Class
Program Output:
Here’s the Output, based on the given program above.
Now, click the Load Image button. This will bring up the OpenDialog box, where you can choose an image, as shown below.
Summary
In this article, we discussed how to use Windows OpenFile Dialog in a Windows Forms application using Microsoft Visual Studio.
Windows Forms is a very useful set of tools. We can use it to make our own file dialog. But this isn’t always necessary.
The most common needs can be met by the OpenFileDialog. It has a lot of parts and qualities.
PREVIOUS
NEXT