Deleting pages

Sitefinity allows you to delete pages through the Pages API.

When deleting a page, you must perform the following:

  1. Get the page node or data.

    When deleting the page, first, you must get the page node or data. For more information about finding a specific page node and data, see Querying pages.

  2. Delete the page.

    After you get the page, you delete it.

  3. Save the changes.

    Finally, you must save the changes.

To delete a page you can use the Native API or the Fluent API.

To delete a page using the Native API, you must use the PageManager class. For more information, see Deleting a page using Native API.

To delete a page using the Fluent API, you must use the page facade. For more information, see Deleting a page using Fluent API.

Deleting a page using Native API

To delete a specific page with the Native API, you use the PageManager class and LINQ queries.

The following example deletes the page with the specified Title:

public void DeletePageNativeAPI(string pageTitleToDelete)
{
    PageManager pageManager = PageManager.GetManager();
    PageData page = pageManager.GetPageDataList().Where(pD => (pD.Title == pageTitleToDelete && pD.Status == ContentLifecycleStatus.Live)).FirstOrDefault();
 
    if (page != null)
    {
        pageManager.Delete(page);
        pageManager.SaveChanges();
    }
}

First, you initialize the PageManager. Then, you get the page node using GetPageDataList and filtering based on the Title and Status properties. To delete the page, you call the Delete method. Finally, you save the changes.

Deleting a page using Fluent API

The following example deletes the page with the specified Title:

public void DeletePageFluentAPI(string pageTitleToDelete)
{
    App.WorkWith().Pages()
        .Where(pN => (pN.Page != null && pN.Page.Title == pageTitleToDelete))
        .Delete()
        .SaveChanges();
}

First, you get the page node of the page data with the specified Title. Then, you delete the page using the Delete method. Finally, you save the changes.

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK