Use of SaveAs file dialog box in C#

 
This example requires one richtextbox control named ‘RichTextBox1’ and one button control named ‘btnSave’ on the windows form.


Drag and drop ‘SaveFiledialog’ from toolbox. This allows you to save the file that’s currently in the Rich text box.
 
 
 
 
Now Create the Click event of save button (you can generate click event through double click your Save button item). This will open up the code for this item:

private void btnSave_Click(object sender, EventArgs e)
    {
    }

Add code like this:

private void btnSave_Click(object sender, EventArgs e)
   {
       saveFileDialog1.InitialDirectory = "c";
       saveFileDialog1.Title = "Save as RTF file";
       saveFileDialog1.Filter = "Rtf files|*.rtf";       
       if (saveFileDialog1.ShowDialog() == DialogResult.OK)
          {
             richTextBox1.SaveFile(saveFileDialog1.FileName);
          }
}

We can find file path on which we want to save the rtf file through saveFileDialog1.FileName
Now run this application and enter some text in rich textbox and click on save. Select the file path and press ok in dialog box. Rtf file will be create on selected path.