How to terminate SharePoint list workflow programmatically - in an event receiver? RRS feed

  • Question

  • Hi, I use SharePoint 2010.

    I have a list workflow, which I need to terminate if a particular column value changes to TRUE.
    I plan to do this in an event receiver with C# code. 
    How to detect the workflow and how to terminate it?

    Thanks so much in advance for your help.

    Friday, July 19, 2013 11:27 PM


  • Hi,

    I understand that you want to terminate a list workflow programmatically in an event receiver. You can create an itemupdated event handler. Try the sample code below:
    using (SPSite site = new SPSite(properties.SiteId)) 
    using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
     SPWorkflowManager manager = site.WorkflowManager;
     SPListItem item = web.Lists[properties.ListTitle].GetItemById(properties.ListItemId);
     foreach (SPWorkflow workflow in manager.GetItemActiveWorkflows(item))
    foreach (SPWorkflowTask t in workflow.Tasks)
    t["Status"] = "Canceled"; t.Update();

    For more information, please refer to this site:

    How to cancel a workflow programmatically: 

    Entan Ming

    Entan Ming
    TechNet Community Support

    Sunday, July 21, 2013 6:11 AM