简体   繁体   中英

Append to RTF file in C#

Is there a way to append content to a RTF file format? I need it for the following functionality. When adding a Paragraph to the FlowDocument, I need to write it to the RTF file, also. Till now I was saving the entire FlowDocument into the file. In addition, I don't want to keep the more than 10000 Paragraphs in memory.

Here is a piece of code I tried but it didn't work.

     TextRange tr = new TextRange(flowDoc.ContentStart, flowDoc.ContentEnd);
     FileStream file = new FileStream(path, FileMode.Append,FileAccess.ReadWrite, FileShare.Read);
     tr.Save(file, DataFormats.Rtf);
     TextWriter tw = new StreamWriter(file);
     tw.Write(file.ToString());
     tw.Close();

Thanks!

The only thing I could think of is to use a temp RichTextBox. Copy and paste into it all the formatted text you want to append, and then copy and paste from it. You will need another temp Richtextbox to convert from rtf code to formatted text before copying and pasting to the other one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM