This is a migrated thread and some comments may be shown as answers.

Import a word range throws Dir Not Found

1 Answer 71 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 10 Sep 2012, 09:11 PM
I am trying to imjport a word range into a rtb document and get a Dir not found exception.

Microsoft.Office.Interop.Word.Range oPage;
oPage = _WordDoc.Range(beginChar, endChar);
string sXML = oPage.WordOpenXML;
Telerik.WinControls.RichTextBox.Model.RadDocument document = null;         
Telerik.WinControls.RichTextBox.FormatProviders.IDocumentFormatProvider docProvider = new Telerik.WinControls.RichTextBox.FileFormats.OpenXml.Docx.DocxFormatProvider();
byte[] byteArray = Encoding.ASCII.GetBytes(sXML);
document = docProvider.Import(byteArray); <== Exception thrown here
The sXML var can be put into a word doc and saved so I know the sXML data is not corrupt
ex.
Microsoft.Office.Interop.Word.Document oTempDoc = _WordApp.Documents.Add();
oTempDoc.Paragraphs[1].Range.InsertXML(sXML);

I also tried using a stream and got the same error
MemoryStream stream = new MemoryStream(byteArray);
document = docProvider.Import(stream);

So far the only thing that seems to work is to save the word fragment to a file and the turn around and import the file, but that is a lot of hoop jumping to get the word fragment into the rtb.
Any suggestions?
Mike

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 12 Sep 2012, 01:59 PM
Hi Mike,

There is no way to import an OpenXML fragment. You should have a valid docx document that can be imported. Presently, you can import only the whole document.

All the best,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Mike
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or