FileDialog.DefaultExt Properti

Definisi

Mendapatkan atau mengatur nilai yang menentukan string ekstensi default yang akan digunakan untuk memfilter daftar file yang ditampilkan.

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

Nilai Properti

String ekstensi default. Default adalah Empty.

Contoh

Contoh berikut menunjukkan cara membuat OpenFileDialog yang berisi nama file default dan jenis ekstensi.

// 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

Keterangan

String ekstensi harus berisi periode awal. Misalnya, atur properti ke DefaultExt ".txt" untuk memilih semua file teks.

Secara default, AddExtension properti mencoba menentukan ekstensi untuk memfilter daftar file yang ditampilkan dari Filter properti . Jika ekstensi tidak dapat ditentukan dari Filter properti , DefaultExt akan digunakan sebagai gantinya.

Berlaku untuk