سؤال

I want to save data from richTextBox to existing file called "data.rtf" but problem is that it overwrites the file.

I am using this code:

richTextBox.SaveFile(path, RichTextBoxStreamType.RichText);

I want to append Text

هل كانت مفيدة؟

المحلول

you can use this:

using (StreamWriter writer = File.AppendText(FilePath))
 {
    writer.WriteLine(richTextBox1.text);
 }

نصائح أخرى

Try to store the previous data in a variable, later set the richTextBox's data to previous + new and then call the SaveFile method.

Something like this

var olddata = DataFromExistingFile;
var newdata = old + RichTextBoxStreamType.RichText;

then

richTextBox.SaveFile(path, newdata);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top