共用方式為


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.Value)
{
    // 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 則將改用。

適用於