Home > DeveloperSection > Articles > SaveFileDialog in CSharp .NET

SaveFileDialog in CSharp .NET

C# C# 
0 Comment(s)
 4726  View(s)
Rate this:

SaveFileDialog in C#.Net

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


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.



MessageBox.Show("File Saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

Don't want to miss updates? Please click the below button!

Follow MindStick