Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Save file Dialog Box using C#

I need to implement something similar to Notepads' save option. Assuming I have a button placed next to a RichTextBox, what I want is, when this button is clicked, a Dialogue box will open up, which will look similar to the one that appears when Save As is clicked. I would like to save the content of the RichTextBox in text format, by entering the name of file in the Save Dialogue box.

like image 643
Shamim Hafiz - MSFT Avatar asked Sep 14 '11 11:09

Shamim Hafiz - MSFT


People also ask

How do I save a dialog box save in C#?

To save a file using the SaveFileDialog component. Display the Save File dialog box and call a method to save the file selected by the user. Use the SaveFileDialog component's OpenFile method to save the file. This method gives you a Stream object you can write to.

What is OpenFileDialog C#?

C# OpenFileDialog control allows us to browse and select files on a computer in an application. A typical Open File Dialog looks like Figure 1 where you can see Windows Explorer like features to navigate through folders and select a file.

Is used to open the Save As dialogue box?

By pressing F12, Save As dialogue box will open. Ctrl + O is the shortcut key to open an Open dialogue box.


1 Answers

private void Save_As_Click(object sender, EventArgs e)
{
  SaveFileDialog _SD = new SaveFileDialog(); 
  _SD.Filter = "Text File (*.txt)|*.txt|Show All Files (*.*)|*.*";
  _SD.FileName = "Untitled"; 
  _SD.Title = "Save As";
  if (__SD.ShowDialog() == DialogResult.OK)
  {
   RTBox1.SaveFile(__SD.FileName, RichTextBoxStreamType.UnicodePlainText);
  }
}
like image 70
Overlock Avatar answered Oct 03 '22 16:10

Overlock