How is it possible to cancel all running workflows in a SharePoint (2010) List?
I found this script via technet.
CODE:
using (SPSite oSite = new SPSite("<your url>"))
{
foreach (SPWeb oWeb in oSite.AllWebs)
{
oWeb.AllowUnsafeUpdates = true;
// stop list workflows
foreach (SPList list in oWeb.Lists)
{
foreach (SPListItem oItem in list.Items)
{
foreach (SPWorkflow workflow in oItem.Workflows)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
}
}
// stop site workflows
foreach (SPWorkflow workflow in oWeb.Workflows)
{
SPWorkflowManager.CancelWorkflow(workflow);
}
oWeb.AllowUnsafeUpdates = false;
oWeb.Dispose();
}
}
Many thanks for your help.