Monday, December 14, 2009

Delete all the items from a custom list or a document library.



SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite spSite = new SPSite("http://testserver/spsite"))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
SPList objLst = spWeb.Lists["List Name"];
SPListItemCollection objCol = objLst.Items;

for (int count = 0; count <= objCol.Count - 1; count++) { objLst.Items.Delete(0); } } } });

No comments:

Post a Comment