# Document Variables

*Document variables* provide a mechanism to store information in the document in a key-value format. [`DocumentVariableField`](https://docs.telerik.com/devtools/document-processing/api/telerik.windows.documents.flow.model.fields.documentvariablefield) is a [Field](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/fields) element used to access and display the value that corresponds to the given field-argument. The argument is the name of the variable.

## DocumentVariableCollection

[`RadFlowDocument`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument) has a `DocumentVariableCollection` property, which holds document variable records. The collection maps string keys to string values. You can add a record through an indexer or with the collection's `Add()` method. **Example 1** demonstrates both approaches.

**Example 1: Add Name and Job records to the document variable collection**

```C#
RadFlowDocument document = new RadFlowDocument();
document.DocumentVariables["Job"] = "Software Engineer";
document.DocumentVariables.Add("Name", "Nancy Davolio");
```

The code in **Example 1** adds two document variables—*"Name"*, which evaluates to *"Nancy Davolio"*, and *"Job"* with a *"Software Engineer"* value.

You can use the same two methods to modify the value of an existing variable in the collection.

To remove defined variables, use the `Remove()` method of the variables collection. It accepts the name of the variable as a parameter.

**Example 2: Remove the Job document variable from the collection**

```C#
document.DocumentVariables.Remove("Job");
```

## Field Syntax

| Syntax                     |
| :------------------------- |
| { **DOCVARIABLE** "Name" } |

The syntax of a document variable field code is demonstrated in **Figure 1**.

**Figure 1: Document variable field code syntax**
![Telerik RadWordsProcessing DOCVARIABLE field syntax diagram showing the DOCVARIABLE field type and the Name argument that maps to a document variable](https://www.telerik.com/document-processing-libraries/documentation/assets/2904dc7d963a53fb1cc55558cb612058/radwordsprocessing_concepts_document_variables_01.png)

## Inserting

You can insert a `DocumentVariableField` through the [`RadFlowDocumentEditor`](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/editing/radflowdocumenteditor)'s `InsertField()` method.
**Example 3** shows insertion of the field created in **Example 1**.

**Example 3: Insert a DOCVARIABLE field that displays the Name document variable value**

```C#

RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
editor.InsertField("DOCVARIABLE Name", "«Nancy Davolio»");
```

## See Also

* [Working with Fields](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/fields/fields)
* [RadFlowDocument](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument)
