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 reference the Telerik.WinControls.RichTextEditor.dll and add the following namespace:

  • Telerik.WinForms.Documents.FormatProviders.Txt

Import

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

Import Document from a File

TxtFormatProvider provider = new TxtFormatProvider();
using (Stream input = File.OpenRead(@"..\..\RichTextEditor\ImportExport\Sample.txt"))
{
    this.radRichTextEditor1.Document = provider.Import(input);
}

Dim provider As TxtFormatProvider = New TxtFormatProvider()
Using input As Stream = File.OpenRead("..\..\RichTextEditor\ImportExport\Sample.txt")
    Me.radRichTextEditor1.Document = provider.Import(input)
End Using

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

Import Document from a String

TxtFormatProvider provider = new TxtFormatProvider();
this.radRichTextEditor1.Document = provider.Import(input);

Dim provider As TxtFormatProvider = New TxtFormatProvider()
Me.radRichTextEditor1.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.

This example shows how to use TxtFormatProvider to export RadDocument to a file.

Export a Document to a File

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

Dim provider As TxtFormatProvider = New TxtFormatProvider()
Using output As Stream = File.OpenWrite("sample.txt")
    Dim document As RadDocument = Me.radRichTextEditor1.Document
    provider.Export(document, output)
End Using

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

Export a Document to a String

TxtFormatProvider provider = new TxtFormatProvider();
RadDocument document = this.radRichTextEditor1.Document;
string output = provider.Export(document);

Dim provider As TxtFormatProvider = New TxtFormatProvider()
Dim document As RadDocument = Me.radRichTextEditor1.Document
Dim output As String = provider.Export(document)

See Also

In this article
Not finding the help you need? Improve this article