Delete an item and its descendants

Version: 10.4

You can use the Sitecore.Data.Items.Item.Delete method to delete an item and its descendants. For example, to delete the /Sitecore/Content/Home/Sample item in the Master database:

RequestResponse
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");

Sitecore.Data.Items.Item sample = master.GetItem("/sitecore/content/home/sample");

sample.Delete();
Note

The Sitecore.Data.Items.Item.Delete() method deletes the item and all of its descendants.

Note

You cannot delete items that are stored in resource files. If you have copied an item from a resource file to the database, Sitecore deletes it from the database and restores it from the resource file.

Do you have some feedback for us?

If you have suggestions for improving this article,