Name

OpenFileDialog Class

Namespace

System.Windows.Forms

Createable

Yes

Description

Represents a common dialog box for selecting or opening a file.

The OpenFileDialog class has properties for setting the initial appearance and functionality of the file dialog box, a property for returning the filename or names selected by the user, as well as a method for showing the dialog box. An instance of the OpenFileDialog class does not itself open the file, but instead provides the information that allows your code to do this programmatically.

Under VB, the most common use for this dialog box is to get the name of a file from the user, after which we can use VB’s functions to open that file.

An OpenFileDialog object can be instantiated as follows:

Dim oOpenDlg As New OpenFileDialog

Selected OpenFileDialog Members

The following is a brief description of some of the more important members of the OpenFileDialog class:

AddExtension property

Gets or sets a Boolean value that determines whether the default file extension is automatically added to the Filename property if the user fails to enter an extension. Its default value is True.

CheckFileExists property

Sets or retrieves a Boolean value indicating whether a warning message should be displayed if the user enters the name of a file that does not exist. The default value is True.

DefaultExt property

Gets or sets a String that defines the default file extension. The string should consist of the file extension only without a period.

FileName property ...

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.