Edit this page
Available for: UI for ASP.NET AJAX | UI for ASP.NET MVC | UI for WPF | UI for WinForms

Using DocxFormatProvider

DocxFormatProvider makes it easy to import and export RadFlowDocument to/from docx format, preserving the entire document structure and formatting.

All you have to do in order to use DocxFormatProvider is add references to the assemblies listed below:

  • Telerik.Windows.Documents.Core.dll
  • Telerik.Windows.Documents.Flow.dll
  • Telerik.Windows.Zip.dll

Import

In order to import a docx document, you need to use the Import() method of DocxFormatProvider.

The code in Example 1 shows how to use DocxFormatProvider to import a docx document from a file.

[C#] Example 1: Import document from a file

DocxFormatProvider provider = new DocxFormatProvider();
using (Stream input = File.OpenRead("Sample.docx"))
{
    RadFlowDocument document = provider.Import(input);
}

And here is how you can import a document from byte array containing the docx document:

[C#] Example 2: Import document from a byte array

DocxFormatProvider provider = new DocxFormatProvider();
RadFlowDocument document = provider.Import(input);

The resulting RadFlowDocument can be manipulated like any code-generated document.

Export

In order to export a document to docx, you need to use the Export() method of DocxFormatProvider.

Example 3 shows how to use DocxFormatProvider to export RadFlowDocument to a file.

[C#] Example 3: Export a document to a file

DocxFormatProvider provider = new DocxFormatProvider();
using (Stream output = File.OpenWrite("Sample.docx"))
{
    RadFlowDocument document = CreateRadFlowDocument();
    provider.Export(document, output);
}

You can also export the document to a byte array and preserve it in a database.

[C#] Example 4: Export a document to a byte array

DocxFormatProvider provider = new DocxFormatProvider();

RadFlowDocument document = CreateRadFlowDocument();
byte[] output = provider.Export(document);

The resulting documents can be opened in any application that supports docx documents.