I have created a visual studio workflow (ShaerPoint 2010 sequential workflow).

When the workflow is started I am managing the permission on the workflow item. But I have a requirement that when workflow is terminated by user while it is running then I want to revert the permission to parent's permission.

Which event is triggered by SharePoint when the workflow is terminated? I did not find such event receiver from this link.

What am I missing?

1 Answer 1


After googling for hours I came to an answer that rather to trigger any workflow event we can attach an event receiver (i.e. Item Added) to workflow history list. And in ItemAdded() method we can perform the task. In my case, if the workflow is cancelled then I want to reset the permission of workflow item.

So the declaration for event receiver would be as below:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="Lists/Workflow History">
        <Assembly>Assembly Specification</Assembly>

The coding for event receiver will be as follows:

public override void ItemAdded(SPItemEventProperties properties)
        SPListItem addedItem = properties.ListItem;
        // getting web.
        SPWeb web = properties.Web;
        // getting qms document library.
        SPList List = web.Lists[ListTitle];
        if (List != null)
            // getting the list id from added item.
            Guid listId = new Guid(Convert.ToString(addedItem["List"]));
            // check if the history item is for qms documents
            if (List.ID == listId)
                // getting the event type of the workflow.
                int EventType = int.Parse(Convert.ToString(addedItem["Event"]));
                // if the event type of workflow is cancelled then break unique permission and inherit it's parent.
                if ((SPWorkflowHistoryEventType)EventType == SPWorkflowHistoryEventType.WorkflowCancelled)
                    // getting the list item.
                    SPListItem Item = List.GetItemById(Convert.ToInt32(addedItem["Item"]));
                    if (Item.HasUniqueRoleAssignments)
                        // remove unique assignements.

    catch (Exception ex)
    { }
    { }

I think this might help others too!!!


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.