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 則會改用 。

適用於