0

I write WPF application. In this application user copy data from the word document and add it to richtextbox. Then I save this data in sqlite database. But when I get xaml data from data base and do following procedure

// Saving data
StringWriter wr = new StringWriter();
XamlWriter.Save(RichTextBox.Document, wr);

and

FlowDocument doc = XamlReader.Parse(*wrStringValuefromDB*) as FlowDocument;

End of this process richtextbox concatenate some words as follow:enter image description here

I can't understand what is happening here, Please help me.

Now I know that this problem happens some PC or OS. For example, I install application on Windows 8, Windows 8.1, Windows 10 and it work very good. But some PC doesn't. For example: enter image description here

Elvin Mammadov
  • 25,329
  • 11
  • 40
  • 82
  • Why do you use an XamlWriter? Can't you simply store the content in the db? I expect you have an encoding issue somwhere in that code path. – rene Dec 23 '15 at 11:51
  • I am new in WPF. I watched many example for saving richtextbox content to database, and this approach is advanced I saw. – Elvin Mammadov Dec 23 '15 at 11:53
  • @rene, Have you any suggestion to save richtextbox content to database with another way? – Elvin Mammadov Dec 23 '15 at 11:58
  • 1
    You could try to XamlWriter.Save to a MemoryStream, store the byte[] in the db and on retrieval create a memoryStream again from that byte array and use the XamlReader.Load() instead of Parse. But that is all I have to offer. – rene Dec 23 '15 at 12:15
  • thanks, @rene. I will try it – Elvin Mammadov Dec 23 '15 at 12:19
  • Have you determined whether the problem exists in saving/restoring the richtextbox from XAML, or saving/restoring the XAML from sqlite? I.e. if you just write to XAML and immediately restore from XAML, does your rich text box get corrupted? – dbc Jan 03 '16 at 15:46
  • If it is corrupted, Why app works some PC with same text? The data coped from Word file and past into the rchtextbox. – Elvin Mammadov Jan 03 '16 at 15:51
  • 1
    See ... http://stackoverflow.com/questions/829053/how-to-convert-flowdocument-to-rtf Maybe this is your problem!? – Tom Jan 03 '16 at 15:56
  • @Tom, I need formatted text – Elvin Mammadov Jan 03 '16 at 16:37
  • @Elvin Mammadov allthough it's called TextRange() it is formatted Text – Tom Jan 03 '16 at 16:41
  • Ok, I will try its now)) – Elvin Mammadov Jan 03 '16 at 16:42

1 Answers1

2

See ... stackoverflow.com/questions/829053/… Maybe this is your problem!? Allthough it's called TextRange() it is formatted Text.

Tom
  • 252
  • 1
  • 6