Working with documents in the API

The Kentico API allows you to fully manage documents in custom code.

Use the following classes from the CMS.DocumentEngine namespace:

  • TreeNode - represents documents. Encapsulates data from the CMS_Tree and CMS_Document tables, and the coupled data tables of individual document types.
  • TreeProvider - provides management functionality for latest published tree nodes (documents).
  • DocumentHelper - provides static methods for managing the latest edited versions of documents.
  • TreeHelper - provides static methods for loading tree nodes (documents). Allows you to work with documents without creating instances of the TreeProvider class.

Use the API Examples application to see the use of these classes.

Retrieving latest edited documents

  • Retrieving the latest edited version of all documents:

    var documents = DocumentHelper.GetDocuments();
  • Retrieving the latest edited version of documents of a specific class:

    var documents = DocumentHelper.GetDocuments("CMS.Product");
  • Example that retrieves all CMS.Product documents under the /Products/ path that have Apple at the beginning of their DocumentName:

    var documents = DocumentHelper.GetDocuments("CMS.Product").Path("/Products/", PathTypeEnum.Children).Where("DocumentName", QueryOperator.Like, "Apple%");

Retrieving latest published documents

  • Retrieving the latest published version of documents:

    TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
    var documents = tree.SelectNodes();
  • Retrieving the latest published version of documents of a specific class:

    TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
    var documents = tree.SelectNodes("CMS.Product");
  • Example that retrieves all CMS.Product documents under the /Products/ path that have Apple at the beginning of their DocumentName:

    TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
    var documents = tree.SelectNodes("CMS.Product").Path("/Products/", PathTypeEnum.Children).Where("DocumentName", QueryOperator.Like, "Apple%");
On this page

In this section