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

Using HtmlFormatProvider

HtmlFormatProvider makes it easy to import and export RadFlowDocument to/from HTML format, preserving as much as possible of the document structure and formatting. To use HtmlFormatProvider, you should add references to the assemblies listed below:

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

Import

In order to import an HTML document you can use the overloads of the HtmlFormatProvider.Import() method.

Example 1 shows how to use HtmlFormatProvider to import an HTML document from a file.

[C#] Example 1: Import HTML file

using (Stream input = File.Create(@"Sample.html"))
{
    HtmlFormatProvider provider = new HtmlFormatProvider();
    RadFlowDocument document = provider.Import(input);
}

Example 2 shows how you can import an HTML string.

[C#] Example 2: Import HTML string

string html = "<p>hello world!</p>";
HtmlFormatProvider provider = new HtmlFormatProvider();
RadFlowDocument document = provider.Import(html);

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

Export

In order to export a document to HTML you can use the overloads of the HtmlFormatProvider.Export() method.

Example 3 shows how to use the HtmlFormatProvider to export an instance of RadFlowDocument to a file:

[C#] Example 3: Export HTML to file

HtmlFormatProvider provider = new HtmlFormatProvider();
using (Stream output = File.Create("Sample.html"))
{
    RadFlowDocument document = CreateRadFlowDocument();
    provider.Export(document, output);
}

You can also export the document to a string variable like shown in Example 4.

[C#] Example 4: Export HTML to string

RadFlowDocument document = CreateRadFlowDocument();
HtmlFormatProvider provider = new HtmlFormatProvider();
string html = provider.Export(document);