Using DocxFormatProvider
DOCX, a part of Office Open XML, is a zipped, XML-based file format developed by Microsoft for representing word processing documents. RadWordsProcessing supports this format. DOCX is the default target format for Microsoft Word starting with Microsoft Office 2007.
DocxFormatProvider is compliant with the latest Office Open XML standard—ECMA-376 4th edition, December 2012.
DocxFormatProvider allows you to import and export a RadFlowDocument to/from DOCX format. The provider preserves the entire document structure and formatting.
To use DocxFormatProvider, add references to the following packages:
- Telerik.Windows.Documents.Core
- Telerik.Windows.Documents.Flow
Starting with Q2 2025 the Zip Library is no longer used as an internal dependency in the rest of the Document Processing Libraries—PdfProcessing, WordsProcessing, SpreadProcessing, SpreadStreamProcessing. It is replaced by System.IO.Compression. The Telerik Zip Library continues to ship as a standalone library so you can still use it separately.
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 containing the DOCX document:
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 manipulated like any code-generated document.
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 preserve 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 any application that supports DOCX documents.