Recently, on our team site we had misbehaving workflow, which created over 18 million rows in the Workflow History list. Needles to say it consumed bunch of space on our site and caused other issues.
It was not as easy to clean this up, as one would hope. When I tried to delete the offending list I got this error:
Next, I tried to contact our technical support team. Technician informed me that they can’t delete offending list either, they just recently had the same issue with different customer and their recommendation is to manually delete list entries using tabular list view to get bellow 5000 items threshold.
With 18 million rows in my Workflow History list, that would be lots of clicking.
I decided to write simple console application to delete rows in the Workflow History list using SharePoint CSOM.
Basically, there are four simple steps to accomplish this task:
- Open connection to your o365 site
- Set credentials
- Get list
- Batch delete items in the list
Partial code snippet
You will find default batch size set to 250 items in my project. From my testing, making batch size smaller or larger just decreased performance. This was sweet spot for me. In my run, I averaged 850 deleted items per minute. You can test your own processing performance and adjust batch size accordingly.
You can download compiled console application from my OneDrive and you can start deleting items in no time. Run the application by using following command:
deleteworkflowhistory.exe “[yoursiteurl]” “[List Name]” “[User Name]” “[Password]”
Make sure to replace tokens with your own values. If you do not use startup parameters you will be prompted by the application to enter values for each parameter.
If you like to dig little deeper, complete source code for this project is available on my OneDrive as well.
I hope you will find this project useful and it will save you some time while trying to delete items from large lists.