Bob Gatto

Bob Gatto

  • NA
  • 44
  • 8.2k

I cannot access richTextBox1.Document which I need for storing into db

Dec 24 2020 2:51 PM
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:
  1. string rtfText; //string to save to db  
  2. TextRange tr = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);  
  3. using (MemoryStream ms = new MemoryStream())  
  4. {  
  5.     tr.Save(ms, DataFormats.Rtf);  
  6.     rtfText = Encoding.ASCII.GetString(ms.ToArray());  

When I try to add line 2 to my code, I get to richTexBox. but Document cannot be found when I type it.
Now when I added a reference, I selected PresentationFramework, and at the top of my code, added the line:
  1. using System.Windows.Documents;  
  2. using System.Windows.Controls; 
 and I still cannot access richTextBox1.Document. I'm using Visual Stusio 2019 and am using .NET Framework 4.7.2.
 
How can I access  richTextBox.Document?
 
Thanks for the help,
 
Bob Gatto

Answers (6)