Delete content

When deleting a content item, you must delete its master version. This way the every other version of the item will be deleted too. To delete an item, you must perform the following:

  1. Get the master version.

    Get the master version of the content item.

  2. Delete the master version.

    Delete the master version. All other lifecycle versions will be deleted too.

This topic explains how to delete a content item by its ID.

You can perform these actions by using either Native API or Fluent API. Therefore, the sections below provide code snippets for both APIs.

NOTE: In the following examples, news items will be used as content. The code can also be applied to blog posts, list items, events, images, documents, and videos.

Delete an item by the ID of its master version

The following code deletes an item by the ID of its master version.

Native API

 

First, you get an instance of the manager. Then, you get the master version with the specified ID. Then, you mark the item to be deleted by calling the Delete method of the manager with the master version as an argument. Finally, you save the changes.

Fluent API

 

First, you get the singular facade of the master version with the specified ID. Then, you call the Delete method to mark the item to be deleted. Finally, you call SaveChanges.

Delete an item by the ID of its live version

The following code deletes an item by the ID of its live version.

Native API

 

First, you get an instance of the manager. Then, you get the live version with the specified ID. Then, you get the master version by callingLifecycle.GetMaster with the live version as an argument. Then, you mark the item to be deleted by calling the Delete method of the manager with the master version as an argument. Finally, you save the changes.

Fluent API

 

First, you get the instance of the live version with the specified ID. Then, you get the ID of the master version by using the manager that is exposed by the singular facade. The you get the singular facade for the master version. Then, to mark the item to be deleted, you call theDelete method. Finally, you call SaveChanges.

Delete all items

The following code deletes all of the items.

Native API

 

First, you get an instance of the manager. Then, you get the master versions of the available items. You iterate through the collection and mark each item to be deleted. Finally, you save the changes.

Fluent API

 

First, you get the plural facade of the content item. Then, to mark each item to be deleted, you call the Delete method. Finally, you save the changes.

Was this article helpful?