Document Variables
Document Variables provide a mechanism to store information in the document in a key-value format. DocumentVariableField is a Field element used to access and display the value, which corresponds to the given field-argument. The argument is the name of the variable.
DocumentVariableCollection
RadFlowDocument has a DocumentVariableCollection property, which holds document variable records. The collection maps string keys to string values. You can add a record in it through an indexer or with the collection's Add() method. Example 1 demonstrates both approaches.
Example 1: Add document variable record
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 will be evaluated to "Nancy Davolio", and "Job" with "Software Engineer" value.
The same two methods can be used to modify the value of an existing variable in the collection.
Removing defined variables can be achieved by using the Remove() method of the variables collection. It accepts the name of the variable as a parameter.
Example 2: Remove document variable record
document.DocumentVariables.Remove("Job");
Field Syntax
Syntax |
---|
{ DOCVARIABLE "Name" } |
The syntax of a document variable field code is pretty simple as demonstrated on Figure 1.
Figure 1: Document variable field code syntax
Inserting
A DocumentVariable field can be inserted through RadFlowDocumentEditor's InsertField() method. Example 3 shows insertion of the field created in Example 1.
Example 3: Insert document variable field
editor.InsertField("DOCVARIABLE Name", "«Nancy Davolio»");