FileDialog.DefaultExt Property

Gets or sets a value that specifies the default extension string to use to filter the list of files that are displayed.

Namespace:  Microsoft.Win32
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: Not mapped to an xmlns.

Public Property DefaultExt As String
<object DefaultExt="string" .../>

Property Value

Type: System.String
The default extension string. The default is Empty.

The extension string must contain the leading period. For example, set the DefaultExt property to ".txt" to select all text files.

By default, the AddExtension property attempts to determine the extension to filter the displayed file list from the Filter property. If the extension cannot be determined from the Filter property, DefaultExt will be used instead.

The following example shows how to create an OpenFileDialog that contains a default file name and extension type.

' Configure open file dialog box 
Dim dlg As New Microsoft.Win32.OpenFileDialog()
dlg.FileName = "Document" ' Default file name
dlg.DefaultExt = ".txt" ' Default file extension
dlg.Filter = "Text documents (.txt)|*.txt" ' Filter files by extension

' Show open file dialog box 
Dim result? As Boolean = dlg.ShowDialog()

' Process open file dialog box results 
If result = True Then 
    ' Open document 
    Dim filename As String = dlg.FileName
End If

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft