Back to Devexpress

How to: Insert Dynamic Content

officefileapi-401197-word-processing-document-api-examples-text-how-to-insert-dynamic-content.md

latest2.0 KB
Original Source

How to: Insert Dynamic Content

  • Apr 15, 2025
  • 4 minutes to read

The following code sample uses the DOCVARIABLE field and RichEditDocumentServer.CalculateDocumentVariable event to insert dynamic (formatted) content. In this example, the DOCVARIABLE field is used to display the DevExpress community website’s RSS feed.

View Example: Word Processing Document API - Insert Dynamic Content

  1. Create a new RichEditDocumentServer object and load a document template, if required.

  2. Insert a DOCVARIABLE field. Use the FieldCollection.Create method, as shown below:

  3. Use another RichEditDocumentServer object to generate or load the target dynamic content. In this example, the GenerateRssFeed method returns this RichEditDocumentServer object.

  4. Handle the RichEditDocumentServer.CalculateDocumentVariable event. Use the RichEditDocumentServer object created in the previous step as the CalculateDocumentVariableEventArgs.Value property value. Identify the field by the CalculateDocumentVariableEventArgs.VariableName property value.

  5. Call the FieldCollection.Update to update all document fields, and save the result.