Delete a List Item Programmatically in SharePoint

The below code demonstrates how to use the SharePoint API to delete a list items programmatically:

Delete an an tem without placing the item in the recycle bin:

using (SPWeb web = siteCollection.AllWebs["thewebname"])
{
  SPList list = web.Lists["Document Library"];
  SPListItem item = list.Items[guid];
  item.Delete();
}

Delete an an tem and place the item in the recycle bin:

using (SPWeb web = siteCollection.AllWebs["thewebname"])
{
  SPList list = web.Lists["Document Library"];
  SPListItem item = list.Items[guid];
  item.Recycle();
}



Array

One Response to “Delete a List Item Programmatically in SharePoint”

  1. Nice! Short and neat examples.
    Even your site theme is appealing.