I have a Windows Form (.NET Framework) with a rich text box and I want to store its data to a database. Through my research, the code I found was:
- string rtfText; //string to save to db
- TextRange tr = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
- using (MemoryStream ms = new MemoryStream())
- {
- tr.Save(ms, DataFormats.Rtf);
- rtfText = Encoding.ASCII.GetString(ms.ToArray());
- }
Now when I added a reference, I selected PresentationFramework, and at the top of my code, added the line:
- using System.Windows.Documents;
- using System.Windows.Controls;
How can I access richTextBox.Document?
Thanks for the help,
Bob Gatto


Amit GuptaRank #190 · 12.8K reputationPosted Dec 24, 2020, 10:05 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Dec 24, 2020, 10:26 AM EST
Bob Gatto47 reputationPosted Dec 24, 2020, 10:36 AM EST
Bob Gatto47 reputationPosted Dec 24, 2020, 11:07 AM EST
Amit GuptaRank #190 · 12.8K reputationPosted Dec 24, 2020, 11:12 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Dec 24, 2020, 11:15 AM EST