I'm a bit new to C# and WPF and experiencing a very frustrating issue storing a richtextbox with formatting to my database using entity framework.
Here is my code.
- namespace simpleton
- public partial class AddNewOE : Window
- {
-
- simpletonDBEntities _db = new simpletonDBEntities();
- public AddNewOE()
- {
- InitializeComponent();
- }
-
- private void insertobBtn_Click(object sender, RoutedEventArgs e)
- {
-
- db_entry newdb_entries = new db_entry()
- {
- ReportDetails = ConvertRtbToBytes(rtfText)
- };
- _db.ob_entries.Add(newOb_entries);
- _db.SaveChanges();
- }
- public static byte[] ConvertRtbToBytes(string richTextBox)
- {
- byte[] data = null; string rtfText;
- 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());
- }
- return data;
- }
- }
-
- }
Please help me debug it, I'm getting the error on the ConvertRtbToBytes Function that... 'string' does not contain definition for 'Document' and no accessible extension method 'Document' accepting a first argument of type string could be found (are you missing a using directive or an assembly reference?)
I am also sure the general code is not Okay, any help will be massively appreciated.