# Using TxtFormatProvider

`TxtFormatProvider` allows you to import and export a `RadFlowDocument` to and from plain text format, preserving the document structure.

To use `TxtFormatProvider`, add references to the following packages:

* `Telerik.Windows.Documents.Core`
* `Telerik.Windows.Documents.Flow`

## Import

To import a plain text document, use the `Import()` method of `TxtFormatProvider`.

**Example 1** shows how to use `TxtFormatProvider` to import a document from a file.

**Example 1: Open a Sample.txt file stream and import it into a RadFlowDocument**

```C#
TxtFormatProvider provider = new TxtFormatProvider();
using (Stream input = File.OpenRead("Sample.txt"))
{
    RadFlowDocument document = provider.Import(input, TimeSpan.FromSeconds(10));
}
```

You can also import a document from a string:

**Example 2: Read plain-text content from a string and import it into a RadFlowDocument**

```C#
TxtFormatProvider provider = new TxtFormatProvider();
string input = File.ReadAllText("sample.txt");
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 plain text, use the `Export()` method of `TxtFormatProvider`.

**Example 3** shows how to use `TxtFormatProvider` to export a `RadFlowDocument` to a file.

**Example 3: Export a RadFlowDocument to a sample.txt file stream**

```C#
TxtFormatProvider provider = new TxtFormatProvider();
using (Stream output = File.OpenWrite("sample.txt"))
{
    RadFlowDocument document = CreateRadFlowDocument();
    provider.Export(document, output, TimeSpan.FromSeconds(10));
}
```

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

**Example 4: Export a RadFlowDocument directly to a plain-text string**

```C#
TxtFormatProvider provider = new TxtFormatProvider();
RadFlowDocument document = CreateRadFlowDocument();

string output = provider.Export(document, TimeSpan.FromSeconds(10));
```

## See Also

* [Timeout Mechanism](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/timeout-mechanism-in-dpl)
* [Automatic Output Stream Clearing on Export](https://www.telerik.com/document-processing-libraries/documentation/common-information/clear-output-stream-on-export)
