Skip to main content

DOCPROPERTY

  • 3 minutes to read

Non-MailMerge field

{ DOCPROPERTY “Name” }

Inserts the value of the document property specified by its name. A name is looked up in the core document property names (Document.DocumentProperties) and subsequently, if not found, in the Document.CustomProperties collection.

Core Document Properties

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

Note

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.

View Example

document.BeginUpdate();

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");
document.Fields.Update();
document.EndUpdate();

The following names are recognized as core document properties:

Name Document Property
Application DocumentProperties.Application
AppVersion DocumentProperties.AppVersion
Author DocumentProperties.Author
Category DocumentProperties.Category
Comments DocumentProperties.Description
Company DocumentProperties.Company
CreateTime DocumentProperties.Created
Keywords DocumentProperties.Keywords
LastPrinted DocumentProperties.LastPrinted
LastSavedBy DocumentProperties.LastModifiedBy
LastSavedTime DocumentProperties.Modified
Manager DocumentProperties.Manager
RevisionNumber DocumentProperties.Revision
Subject DocumentProperties.Subject
Title DocumentProperties.Title

Custom Document Properties

A custom document property is specified by its name in double quotes.

The following code illustrates how to create custom document properties and place them in the document’s storage. The DOCPROPERTY field is used to display property values in the document. Calling the FieldCollection.Update updates all property fields in the document body.

Note

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.

View Example

document.BeginUpdate();
document.AppendText("A new value of MyBookmarkProperty is obtained from here: NEWVALUE!\n");
document.Bookmarks.Create(document.FindAll("NEWVALUE!", SearchOptions.CaseSensitive)[0], "bmOne");
document.AppendText("\nMyNumericProperty: ");
document.Fields.Create(document.Range.End, @"DOCPROPERTY ""MyNumericProperty""");
document.AppendText("\nMyStringProperty: ");
document.Fields.Create(document.Range.End, @"DOCPROPERTY ""MyStringProperty""");
document.AppendText("\nMyBooleanProperty: ");
document.Fields.Create(document.Range.End, @"DOCPROPERTY ""MyBooleanProperty""");
document.AppendText("\nMyBookmarkProperty: ");
document.Fields.Create(document.Range.End, @"DOCPROPERTY ""MyBookmarkProperty""");
document.EndUpdate();

document.CustomProperties["MyNumericProperty"]= 123.45;
document.CustomProperties["MyStringProperty"]="The Final Answer";
document.CustomProperties["MyBookmarkProperty"] = document.Bookmarks[0];
document.CustomProperties["MyBooleanProperty"]=true;

document.Fields.Update();