Import a word range throws Dir Not Found

2 posts, 0 answers
  1. Mike
    Mike avatar
    26 posts
    Member since:
    Dec 2006

    Posted 10 Sep 2012 Link to this post

    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
    Microsoft.Office.Interop.Word.Document oTempDoc = _WordApp.Documents.Add();

    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?
  2. Svett
    Svett avatar
    728 posts

    Posted 12 Sep 2012 Link to this post

    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,
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. DevCraft banner
Back to Top