New to Telerik UI for WinFormsStart a free 30-day trial

How To Import DOC Files

Updated over 6 months ago

Environment

Product VersionProductAuthor
2023.3.1010RadRichTextEditor for WinFormsDinko Krastev

Description

An example demonstrating how import DOC file formats into RadRichTextEditor.

Solution

To load a .doc file format to our WinForms RichTextEditor control you need to follow the below steps.

  • Add a reference to the Telerik.Windows.Documents.Flow.FormatProviders.Doc and Telerik.Windows.Documents.Flow DLLs, located in the Telerik WinForms installation folder.
  • Load the .doc type document using DocFormatProvider from our document processing library. This provider will import the document into RadFlowDocument.
  • Export the RadFlowDocument to a byte array using DocxFormatProvider from the document processing library.
  • The last step is to use WinForms DocxFormatProvider to load and create RadDocument from a byte array.

Implementation

C#
Telerik.Windows.Documents.Flow.FormatProviders.Doc.DocFormatProvider docFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Doc.DocFormatProvider();
Telerik.Windows.Documents.Flow.Model.RadFlowDocument document;
using (Stream str = new FileStream(@"../../Lorem Ipsun.doc", FileMode.Open))
{
    document = docFormatProvider.Import(str);
}

Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider docxFormatProvider =
    new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
byte[] documentArray = docxFormatProvider.Export(document);

var radDocxFormatProvider = new Telerik.WinForms.Documents.FormatProviders.OpenXml.Docx.DocxFormatProvider();
this.radRichTextEditor1.Document = radDocxFormatProvider.Import(documentArray);

See Also