FileDialog.DefaultExt Właściwość

Definicja

Pobiera lub ustawia wartość określającą domyślny ciąg rozszerzenia, który ma być używany do filtrowania listy wyświetlanych plików.

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

Wartość właściwości

Domyślny ciąg rozszerzenia. Wartość domyślna to Empty.

Przykłady

W poniższym przykładzie pokazano, jak utworzyć obiekt OpenFileDialog zawierający domyślną nazwę pliku i typ rozszerzenia.

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

Uwagi

Ciąg rozszerzenia musi zawierać okres wiodący. Na przykład ustaw DefaultExt właściwość na ".txt", aby wybrać wszystkie pliki tekstowe.

Domyślnie AddExtension właściwość próbuje określić rozszerzenie, aby filtrować wyświetlaną listę plików z Filter właściwości . Jeśli nie można określić rozszerzenia z Filter właściwości , DefaultExt zostanie użyte zamiast tego.

Dotyczy