Home > DeveloperSection > Articles > SaveFileDialog in CSharp .NET

SaveFileDialog in CSharp .NET

C# C# 
1 Comment(s)
 5496  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);


By Manish Sahu on   3 months ago

Your words increase my knowledge for sure. Thanks

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

Follow MindStick