Share via


FileDialog.DefaultExt 属性

定义

获取或设置一个值,该值指定用来筛选显示的文件列表的默认扩展名字符串。

public:
 property System::String ^ DefaultExt { System::String ^ get(); void set(System::String ^ value); };
public string DefaultExt { get; set; }
member this.DefaultExt : string with get, set
Public Property DefaultExt As String

属性值

默认扩展名字符串。 默认值为 Empty

示例

以下示例演示如何创建 OpenFileDialog 包含默认文件名和扩展名类型的 。

// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = 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
Nullable<bool> result = dlg.ShowDialog();

// Process open file dialog box results
if (result == true)
{
    // Open document
    string filename = dlg.FileName;
}
' 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

注解

扩展字符串必须包含前导句点。 例如,将 DefaultExt 属性设置为“.txt”以选择所有文本文件。

默认情况下, AddExtension 属性会尝试确定扩展,以从 Filter 属性筛选显示的文件列表。 如果无法从 Filter 属性确定扩展, DefaultExt 将改用 。

适用于