c# savefiledialog filter example

Example: save dialog filter c#

SaveFileDialog textDialog;
public Page()
{
    InitializeComponent();
    textDialog = new SaveFileDialog();
    textDialog.Filter = "Text Files | *.txt";
    textDialog.DefaultExt = "txt";
 }

private void button1_Click(object sender, RoutedEventArgs e)
{
    bool? result = textDialog.ShowDialog();
    if (result == true)
    {
        System.IO.Stream fileStream = textDialog.OpenFile();
        System.IO.StreamWriter sw = new System.IO.StreamWriter(fileStream);
        sw.WriteLine("Writing some text in the file.");
        sw.Flush();
        sw.Close();
    }
}