Can the WPF RichTextBox display binary picture content?

I am trying to display an RTF file (that was created in a legacy system) in a new WPF application and have run into some difficulty. The old RTF file contains a picture formatted as a binary jpegblip which, when read into the RichTextBox, causes this exception:

Unrecognized structure in data format 'Rich Text Format'. Parameter name: stream

I reduced the file down to the bare minimum to isolate the problem and ended up with the following opening line (the binary data has been removed for this post):


This still caused an exception so I converted the binary data to hex and created a new file with the opening line:


The file with the hex data in it was displayed correctly by the control.

Has anyone been able to load a file containing binary picture data into the RichTexBox control, or failing that, is there a difinitive statement as to what the RichTextBox supports from the RTF specification?


I'm not even sure Microsoft knows what RichTextBox implements. Their idea of RTF floats around untethered in space. See MS Word, Wordpad, the numerous legacy Rich Edit controls, etc.

This has some comments that talk about using the COM objects in your .NET code, which are somewhat predictable, but again Microsoft doesn't specify what parts of the spec they follow. Broken tables in RichTextBox control (word wrap) - you can use these in WPF if you wrap them properly.

If you just have to display the document, you might ask if all your users will have Word. Then you might be able to embed the Word document viewer, and presto, problem solved. It's an easy dependency to add if your software is used in an office.

I would probably read up on that format until I knew how it worked. Then in my program, I would read the RTF file into a buffer, grab the raw object data, translate it somehow, replace those objects with updated ones, then pass it to the control.

Need Your Help

How to pass 'this' into a function using JavaScript

javascript javascript-events

I have the following code which is designed to create an onchange event handler for all elements with class name 'State'. The only problem is that I want the element to be passed into the 'StateCha...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.