Using DocxFormatProvider
DOCX is part of Office Open XML, a zipped, XML-based format that Microsoft uses for word-processing documents. RadWordsProcessing supports this format. DOCX is the default format in Microsoft Word starting with Microsoft Office 2007.
DocxFormatProvider follows the Office Open XML ECMA-376 specification. Use it to import DOCX documents into RadFlowDocument instances and export RadFlowDocument instances to DOCX files. The provider preserves the document structure and formatting that both RadWordsProcessing and DOCX support.
To use DocxFormatProvider, add references to these packages:
Telerik.(Windows).Documents.CoreTelerik.(Windows).Documents.Flow
Starting with Q2 2025, Telerik Document Processing no longer uses the Zip Library as an internal dependency in PdfProcessing, WordsProcessing, SpreadProcessing, and SpreadStreamProcessing. The libraries use
System.IO.Compressioninstead. Telerik Zip Library still ships as a standalone library.
Import
To import a DOCX document, use the Import() method of DocxFormatProvider.
The following code shows how to use DocxFormatProvider to import a DOCX document from a file.
Example 1: Open a Sample.docx file stream and import it into a RadFlowDocument
Telerik.Documents.Flow.Model.RadFlowDocument document;
Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider = new Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
using (Stream input = File.OpenRead("Sample.docx"))
{
document = provider.Import(input, TimeSpan.FromSeconds(10));
}
You can also import a document from a byte array that contains the DOCX file:
Example 2: Read a Sample.docx file into a byte array and import it into a RadFlowDocument
Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider = new Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
byte[] input = File.ReadAllBytes("Sample.docx");
Telerik.Documents.Flow.Model.RadFlowDocument document = provider.Import(input, TimeSpan.FromSeconds(10));
The resulting RadFlowDocument can be modified like any document that you create in code.
Export
To export a document to DOCX, use the Export() method of DocxFormatProvider.
The following code shows how to use DocxFormatProvider to export a RadFlowDocument to a file.
Example 3: Export a RadFlowDocument to a Sample.docx file stream
Telerik.Documents.Flow.Model.RadFlowDocument document;
Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider = new Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
using (Stream output = File.OpenWrite("Sample.docx"))
{
document = CreateRadFlowDocument(); // CreateRadFlowDocument() is a custom method that creates a simple instance of RadFlowDocument. You can replace it with the instance you would like to export.
provider.Export(document, output, TimeSpan.FromSeconds(10));
}
You can also export the document to a byte array and store it in a database.
Example 4: Export a RadFlowDocument directly to a DOCX byte array
Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider provider = new Telerik.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
Telerik.Documents.Flow.Model.RadFlowDocument document = CreateRadFlowDocument(); // CreateRadFlowDocument() is a custom method that creates a simple instance of RadFlowDocument. You can replace it with the instance you would like to export.
byte[] output = provider.Export(document, TimeSpan.FromSeconds(10));
The resulting documents can be opened in applications that support DOCX files.