Edit this page

Using TxtFormatProvider

TxtFormatProvider makes it easy to import and export RadDocument to/from plain text format, preserving the document structure.

To use TxtFormatProvider, you should add references to:

  • Telerik.Windows.Documents.dll

Import

In order to import a plain text document, you need to use the Import() method of TxtFormatProvider. Example 1 shows how to use TxtFormatProvider to import a document from a file.

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

TxtFormatProvider provider = new TxtFormatProvider();
using (Stream input = File.OpenRead("Sample.txt"))
{
    RadDocument document = provider.Import(input);
}

And here is how you can import a document from string:

[C#] Example 2: Import document from a string

TxtFormatProvider provider = new TxtFormatProvider();
RadDocument document = provider.Import(input);

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

Export

In order to export a document to plain text, you need to use the Export() method of TxtFormatProvider.

Example 3 shows how to use TxtFormatProvider to export RadDocument to a file.

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

TxtFormatProvider provider = new TxtFormatProvider();
using (Stream output = File.OpenWrite("sample.txt"))
{
    RadDocument document = CreateRadDocument();
    provider.Export(document, output);
}

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

[C#] Example 4: Export a document to a string

TxtFormatProvider provider = new TxtFormatProvider();
RadDocument document = CreateRadDocument();
string output = provider.Export(document);

See Also