Skip to main content

How to: Specify Document Properties in Word Documents

  • 3 minutes to read

This example demonstrates how to append document properties in code.

Specify Standard Document Properties

Use the Document.DocumentProperties property to specify standard document properties, as illustrated below.

This code snippet demonstrates how to set standard document properties and show them in a document using specific fields. The FieldCollection.Update method updates all property fields in the document body.


If the DOCPROPERTY fields are located in the text box, header or footer, they should be updated separately. Use the Section.BeginUpdateHeader - Section.EndUpdateHeader or Section.BeginUpdateFooter - Section.EndUpdateFooter paired methods to obtain the header or footer. The TextBox.Document property allows you to retrieve the text box content and update the corresponding fields.

using XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer()) {
    Document document = wordProcessor.Document;

    document.DocumentProperties.Creator = "John Doe";
    document.DocumentProperties.Title = "Inserting Custom Properties";
    document.DocumentProperties.Category = "TestDoc";
    document.DocumentProperties.Description = "This code demonstrates API to modify and display standard document properties.";

    document.Fields.Create(document.AppendText("\nAUTHOR: ").End, "AUTHOR");
    document.Fields.Create(document.AppendText("\nTITLE: ").End, "TITLE");
    document.Fields.Create(document.AppendText("\nCOMMENTS: ").End, "COMMENTS");
    document.Fields.Create(document.AppendText("\nCREATEDATE: ").End, "CREATEDATE");
    document.Fields.Create(document.AppendText("\nCategory: ").End, "DOCPROPERTY Category");

Built-in Properties in Different Formats

The following table lists the built-in document properties supported in different formats:

Application yes yes yes yes yes no
AppVersion yes yes yes yes yes no
Category yes yes yes yes no no
ContentStatus yes no yes no no no
ContentType yes no no no no no
Company yes yes yes yes yes no
Created yes yes yes yes yes no
Creator yes yes yes yes yes no
Description yes yes yes yes yes no
Identifier yes no no no no no
Keywords yes yes yes yes yes no
Language yes no yes no no no
LastModifiedBy yes yes yes yes yes no
LastPrinted yes yes yes yes yes no
Manager yes yes yes yes yes no
Modified yes yes yes yes yes no
Revision yes yes yes yes yes no
Subject yes yes yes yes yes no
Template yes yes yes yes yes no
Title yes yes yes yes yes yes
Version yes no yes no no no

Create Custom Document Properties

To create a custom document property, use the Document.CustomProperties property to add a new item to the corresponding collection. This can be done in two ways:

  • Use the DocumentCustomProperties.Item property. It sets a value to the property with the name specified in square brackets. If a property with this name does not exist, it is created automatically.
Document document = server.Document;
document.Fields.Create(document.AppendText("\nMyNumericProperty: ").End, "DOCVARIABLE CustomProperty MyNumericProperty");
document.Fields.Create(document.AppendText("\nMyStringProperty: ").End, "DOCVARIABLE CustomProperty MyStringProperty");
document.Fields.Create(document.AppendText("\nMyBooleanProperty: ").End, "DOCVARIABLE CustomProperty MyBooleanProperty");

document.CustomProperties["MyNumericProperty"]= 123.45;
document.CustomProperties["MyStringProperty"]="The Final Answer";

server.CalculateDocumentVariable += DocumentPropertyDisplayHelper.OnCalculateDocumentVariable;
private void SetCustomProperties()
      Document document = server.Document;
      document.CustomProperties.Add("MyNumericProperty", 123.45);
      document.CustomProperties.Add("MyStringProperty", "The Final Answer");
      document.CustomProperties.Add("MyBookmarkProperty", document.Bookmarks[0]);
      document.CustomProperties.Add("MyBooleanProperty", true);