---
title: Working with pages in the API
related:
  - https://docs.kentico.com/k81/managing-website-content/working-with-pages.md
  - https://docs.kentico.com/k81/developing-websites/defining-website-data-structure/page-types.md
  - https://docs.kentico.com/k81/developing-websites/developing-sites-using-the-mvc-framework/code-generators.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

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

Use the following classes from the **CMS.DocumentEngine** namespace:

- **TreeNode** - represents pages. Encapsulates data from the _CMS\_Tree_ and _CMS\_Document_ tables, and the coupled data tables of individual page types.
- **TreeProvider** - provides management functionality for latest published tree nodes (pages).
- **DocumentHelper** - provides static methods for managing the latest edited versions of pages.
- **TreeHelper** - provides static methods for loading tree nodes (pages). Allows you to work with pages without creating instances of the _TreeProvider_ class.

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

### Retrieving latest edited pages

- Retrieving the latest edited version of all pages:

  ```csharp

  var pages = DocumentHelper.GetDocuments();

  ```
- Retrieving the latest edited version of pages of a specific class:

  ```csharp

  var pages = DocumentHelper.GetDocuments("CMS.Product");

  ```
- Example that retrieves all _CMS.Product_ pages under the _/Products/_ path that have _Apple_ at the beginning of their _DocumentName_:

  ```csharp

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

  ```

### Retrieving latest published pages

- Retrieving the latest published version of pages:

  ```csharp

  TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
  var pages = tree.SelectNodes();

  ```
- Retrieving the latest published version of pages of a specific class:

  ```csharp

  TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
  var pages = tree.SelectNodes("CMS.Product");

  ```
- Example that retrieves all _CMS.Product_ pages under the _/Products/_ path that have _Apple_ at the beginning of their _DocumentName:_

  ```csharp

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

  ```
