10.4
  1. Delete an item and its descendants

Delete the descendants of an item

You can use the Sitecore.Data.Items.Item.DeleteChildren() method to delete the descendants of an item. For example, to delete the descendants of the /Sitecore/Content/Home item in the Master database:


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

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

sample.DeleteChildren();
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.

If you have suggestions for improving this article, let us know!