using new line in saveFileDialog
-
hi, when use the following code SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Text Files|*.txt|Comma Seperated Files|*.csv|All Files|*.*"; dlg.InitialDirectory = @"C:\"; saveFileDialog1.OverwritePrompt = true; if (dlg.ShowDialog() == DialogResult.OK) { using (System.IO.StreamWriter writer = new System.IO.StreamWriter(dlg.FileName)) { writer.Write(this.richTextBox1.Text); writer.Flush(); } } it saves a file but unfortunately it saves it without newline characters ie.,. I want to save my work as it is displayed in the multiline text box.can you help me please
Don't wait to hear a word of thanks from anybody when you help them instead ask them to help three other people and ask them to continue in chain.
-
hi, when use the following code SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Text Files|*.txt|Comma Seperated Files|*.csv|All Files|*.*"; dlg.InitialDirectory = @"C:\"; saveFileDialog1.OverwritePrompt = true; if (dlg.ShowDialog() == DialogResult.OK) { using (System.IO.StreamWriter writer = new System.IO.StreamWriter(dlg.FileName)) { writer.Write(this.richTextBox1.Text); writer.Flush(); } } it saves a file but unfortunately it saves it without newline characters ie.,. I want to save my work as it is displayed in the multiline text box.can you help me please
Don't wait to hear a word of thanks from anybody when you help them instead ask them to help three other people and ask them to continue in chain.
Are you viewing your file with notepad.exe? RichTextBox delimits the lines with a
\n
instead of the windows typical\r\n
, that's why some editors have troubles with it. Proper editors like NotePad++ or UltraEdit have no problems with a\n
on windows. You might do that:writer.Write(richTextBox1.Text.Replace("\n", Environment.NewLine));