---
title: "Working with Text Document in C#"
---

```

## Purpose Summary

This page explains how to work with plain text documents using Aspose.Words.

```

In this article, we will learn what options can be useful for working with a text document via Aspose.Words. Please note that this is not a complete list of available options, but only an example of working with some of them.

## Add Bi-Directional Marks

You can use the [AddBidiMarks](https://reference.aspose.com/words/net/aspose.words.saving/txtsaveoptions/addbidimarks/) property to specify whether to add bi-directional marks before each BiDi run when exporting in plain text format. Aspose.Words inserts Unicode Character 'RIGHT-TO-LEFT MARK' (U+200F) before each bi-directional Run in the text. This option corresponds to "Add bi-directional marks" option in MS Word File Conversion dialogue when you export to a Plain Text format. Note that it appears in dialogue only if any of Arabic or Hebrew editing languages are added in MS Word.

The following code example shows how to use **AddBidiMarks** property. The default value of this property is *false*:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "add-bidi-marks.cs" >}}

## Recognize List Items During Loading TXT

Aspose.Words can import list item of a text file as list numbers or plain text in its document object model. The [DetectNumberingWithWhitespaces](https://reference.aspose.com/words/net/aspose.words.loading/txtloadoptions/detectnumberingwithwhitespaces/) property allows specifying how numbered list items are recognized when a document is imported from plain text format:

* If this option is set to *true*, whitespaces are also used as list number delimiters: list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both whitespaces and dot (".") symbols.

* If this option is set to *false*, lists recognition algorithm detects list paragraphs, when list numbers end with either dot, right bracket or bullet symbols (such as "•", "*", "-" or "o").

The following code example shows how to use this property:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "detect-numbering-with-whitespaces.cs" >}}

## Handle Leading and Trailing spaces During Loading TXT

You can control the way of handling leading and trailing spaces during loading TXT file. The leading spaces could be trimmed, preserved or converted to indent and trailing spaces could be trimmed or preserved.

The following code example shows how to trim leading and trailing spaces while importing TXT file:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "handle-spaces-options.cs" >}}

## Detect Document Text Direction

Aspose.Words provides the [DocumentDirection](https://reference.aspose.com/words/net/aspose.words.loading/txtloadoptions/documentdirection/) property in the [TxtLoadOptions](https://reference.aspose.com/words/net/aspose.words.loading/txtloadoptions/) class to detect the text direction (RTL / LTR) in the document. This property sets or gets document text directions provided in the [DocumentDirection](https://reference.aspose.com/words/net/aspose.words.loading/documentdirection/) enumeration. The default value is left to *right*.

The following code example shows how to detect text direction of the document while importing TXT file:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "document-text-direction.cs" >}}

## Export Header and Footer in Output TXT

If you want to export header and footer in output TXT document, you can use the [ExportHeadersFootersMode](https://reference.aspose.com/words/net/aspose.words.saving/exportheadersfootersmode/) property. This property specifies the way headers and footers are exported to the plain text format.

The following code example shows how to export headers and footers to plain text format:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "export-headers-footers-mode.cs" >}}

## Export List Indentation in Output TXT

Aspose.Words introduced the [TxtListIndentation](https://reference.aspose.com/words/net/aspose.words.saving/txtlistindentation/) class that allows specifying how list levels are indented while exporting to a plain text format. While working with [TxtSaveOption](https://reference.aspose.com/words/net/aspose.words.saving/txtsaveoptions/), the [ListIndentation](https://reference.aspose.com/words/net/aspose.words.saving/txtsaveoptions/listindentation/) property is provided to specify the character to be used for indenting list levels and count specifying how many characters to use as indentation per one list level.

The default value for character property is '\0' indicating that there is no indentation. For count property, the default value is 0 which means no indentation.

### Using Tab Character

The following code example shows how to export list levels using tab characters:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "use-tab-for-list-indentation.cs" >}}

### Using Space Character

The following code example shows how to export list levels using space characters:

{{< gist "aspose-words-gists" "ddafc3430967fb4f4f70085fa577d01a" "use-space-for-list-indentation.cs" >}}

------

## FAQ

1. **Q:** How can I add bi‑directional marks when saving a TXT file?
   **A:** Set `TxtSaveOptions.AddBidiMarks` to `true` before calling `Document.Save`. This inserts the Unicode RIGHT‑TO‑LEFT MARK (U+200F) before each RTL run, matching the "Add bi‑directional marks" option in Word.

2. **Q:** Which option controls list detection while loading a plain‑text file?
   **A:** Use `TxtLoadOptions.DetectNumberingWithWhitespaces`. When set to `true`, whitespaces are treated as delimiters for numbered lists; when `false`, only dots, brackets or bullet symbols are recognized.

3. **Q:** How do I preserve leading and trailing spaces when importing a TXT document?
   **A:** Configure `TxtLoadOptions` properties `LeadingSpacesOptions` and `TrailingSpacesOptions` before loading the document.

4. **Q:** Can I export headers and footers to a plain‑text file?
   **A:** Yes. Set `TxtSaveOptions.ExportHeadersFootersMode` to `ExportHeadersFootersMode.All` (or `PrimaryOnly`) to include header/footer text in the saved TXT output.

5. **Q:** How can I control indentation of list levels in the exported TXT?
   **A:** Create a `TxtListIndentation` instance, set its `Character` (e.g., `'\t'` for tabs or `' '` for spaces) and `Count` (number of characters per level), then assign it to `TxtSaveOptions.ListIndentation`.