Howard Bash
asked on
SharePoint ListItemCollection deleting listems
I need to delete listitems within a listitemcollection based on the value of a column. It fails as I am deleting items within the collection so the enumeration throws exception on next iteration after a delete. The code follows:
public static void DeletListItemsByParentID(string siteUrl, string listName, string ListIDColumnName, double ItemID)
{
try
{
using (ClientContext ctx = new ClientContext(siteUrl))
{
ListItemCollection lic = SharePointHelper.GetListItems(ctx, listName);
foreach (ListItem l in lic)
{
object i = l[ListIDColumnName];
if ((double)i == ItemID)
{
l.DeleteObject();
}
}
ctx.ExecuteQuery();
}
}
catch (SystemException ex)
{
throw new SystemException("Exception thrown in SharePointHelper.DeletListItemsByParentID", ex);
}
}
ASKER
Do you have a C# solution? The offered solution in javascript.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you will have to push the list item to another client object and then delete the items:
http://www.jopache.com/blog/batch-delete-sharepoint-list-items-with-javascript
HTH
Rainer