Thursday, August 7, 2008

Delete some of the items from a list or library

Scenario:
You want to selectively delete items from a list or library

Code:

SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists["List_Name"].Items;
int itemCount = listItems.Count;

for (int k=0; k<itemCount; k++)
{
SPListItem item = listItems[k];

if (item["Title"].ToString()=="Old Books")
{
listItems.Delete(k);
break;

}
}

0 comments: