using (SPSite siteCollection = new SPSite("http://localhost"))
{
using (SPWeb site = siteCollection.OpenWeb())
{
SPList list1 = site.Lists["TestList"];
for (int i = list1.Items.Count - 1; i >= 0; i--)
{
list1.Items.Delete(i);
}
}
}
The method deletes the data permanently from the SharePoint and it does not send the data to Recycle Bin.
So upon doing little search I found Recycle method of SPListItem Class. This method will delete the data from the list and send the data to the Recycle Bin.
So to delete the data with SharePoint Object Model from a SharePoint List so that the deleted data goes to Recycle Bin use the following code:
using (SPSite siteCollection = new SPSite("http://localhost"))
{
using (SPWeb site = siteCollection.OpenWeb())
{
SPList list1 = site.Lists["TestList"];
for (int i = list11.Items.Count - 1; i >= 0; i--)
{
SPListItem olistitem = list11.Items[i];
olistitem.Recycle();
}
}
}
No comments:
Post a Comment