articles

Home / DeveloperSection / Articles / SaveFileDialog in CSharp .NET

SaveFileDialog in CSharp .NET

Anonymous User9121 18-Jul-2010

Here I am going to demonstrate how to use SaveFileDialog in C#.Net.

 SaveFileDialog in CSharp .NET

Example

Creating stream for writing file

 Stream str;
//creating object of SaveFileDialog
   SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  //creating filter to saveFileDialog
  saveFileDialog1.Filter = "Text File|*.txt";
  //checking whether saved button is pressed or not.
  if (saveFileDialog1.ShowDialog() == DialogResult.OK)
     {
        if ((str = saveFileDialog1.OpenFile()) != null)
         {
         //creating stream writer.
          StreamWriter wText = new StreamWriter(str);
             //writing text to file.
            wText.Write(" your text");
             //closing stream.
              str.Close();
          }
MessageBox.Show("FileSaved!""Information"MessageBoxButtons.OK, MessageBoxIcon.Information);

 


Updated 11-Jul-2020
I am a content writter !

Leave Comment

Comments

Liked By