How to save an stringbuilder's content to text file using SaveFileDialog?

You want the WriteAllText function. Using (SaveFileDialog dialog = new SaveFileDialog()) { if (dialog. ShowDialog(this) == DialogResult.

OK) { File. WriteAllText(dialog. FileName, yourStringBuilder.ToString()); } }.

StringBuilder.ToString() will get you the string. This link will show you how to write text to a file. This link will show you how to call SaveFileDialog and pass a stream to it to save.

Hope that helps.

Think no longer... using System; using System.Collections. Generic; using System. ComponentModel; using System.

Data; using System. Drawing; using System. Linq; using System.

Text; using System.Windows. Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { StringBuilder sb = new StringBuilder(); public Form1() { InitializeComponent(); sb. Append("This is going "); sb.

Append("to be saved to a text file"); } private void button1_Click(object sender, EventArgs e) { using (SaveFileDialog dlg = new SaveFileDialog()) { if (dlg.ShowDialog() == DialogResult. OK) { string fileName = dlg. FileName; SaveToFile(fileName); } } } private void SaveToFile(string fileName) { System.IO.

TextWriter w = new System.IO. StreamWriter(fileName); w. Write(sb.ToString()); w.Flush(); w.Close(); } }.

– Jon Grant Oct 23 '08 at 18:41 Pretty cool...I've not seen that function. I have learned something new today:D – sbeskur Oct 23 '08 at 19:08.

StringBuilder.ToString() can be passed to the TextStream.Write() method after creating the file. Using the SaveFileDialog class, you can let the user select path and file name - in a standard way. Detailed examples in the doc.

The OpenFileDialog will, by default, require the file to exist. The SaveFileDialog class is the way to go. – Jon Grant Oct 23 '08 at 18:29 the content of the file to be saved is in the stringbuilder – Anonymous123 Oct 23 '08 at 18:29.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions