articles

home / developersection / articles / savefiledialog in csharp .net

SaveFileDialog in CSharp .NET

Anonymous User 9.24 K 18-Jul-2010

Here I am going to demonstrate how to use SaveFileDialog in C#.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);

 


c# c# 
Updated 11-Jul-2020

I am a content writter !

Leave Comment

Comments

Liked By