1

I need to delete the content of the workflow history list that has 18 million items.

I've tried the CSOM code below but it throws a time out error. I couldn't index any columns either through list settings or CSOM. Any help to get rid of these items is greatly appreciated.

This is the CSOM code I've used:

ClientContext context = new ClientContext("https://siteurl");
context.Credentials = new NetworkCredential("username", "pwd", "domain");

List list = context.Web.Lists.GetByTitle("Workflow History");
CamlQuery query = new CamlQuery();
listvalue = txtURL.Text.ToString();
query.ViewXml = "<view><query><where><Eq><FieldRef Name='ID'><Value Type='Number'>1</Value></Eq></where></query></view>";

// query.ViewXml = "<view><query></query><Rowlimit>10</Rowlimit></view>";    

ListItemCollection listitemcoll = list.GetItems(query);
context.Load(listitemcoll);

context.ExecuteQuery();
// the code throws error here
foreach (ListItem li in listitemcoll)
{
    li.DeleteObject();
}
context.ExecuteQuery();
2

1 Answer 1

2

Default List View Threshold limit is 5000. it will not allow you to delete more than 5000 items from single query operation.

  1. You can use batch command to achieve this. Refer this link 1, link 2
  2. You can run timer job from central admin : SharePoint Workflow Auto Cleanup Timer Job (But it will remove both workflow history as well as task list items who completes 60 days from creation. You can change this time also)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.