First published on TECHNET on Jun 06, 2012
1: EventFiringHandler handler = new EventFiringHandler();
2: SPSite mysite = new SPSite("http://localhost/");
3: SPWeb web = mysite.OpenWeb();
4: SPList list = web.Lists["Tasks"];
5: SPListItem item = list.GetItemById(<taskItemID>);
6: Hashtable hashT = new Hashtable();
7: hashT.Add("Title","MyNewTitle");
8: handler.DisableHandleEventFiring();
9: SPWorkflowTask.AlterTask(item, hashT, true);
Hope this helps!
This post is a contribution from Nishand Vasudevan, an escalation engineer with the SharePoint Developer Support team.
Disabling the event receivers can stop the workflow events. For example, disabling the event can stop workflow from starting and could stops firing events like OnTaskChanged.
The below code will not trigger OnTaskChanged event that otherwise would. The code snippet is to depict what you shouldn’t be doing in your code and it’s an illustrative example.
1: public class EventFiringHandler : SPItemEventReceiver
2: {
3: public void DisableHandleEventFiring()
4: {
5: this.EventFiringEnabled = false;
6: }
7:
8: public void EnableHandleEventFiring()
9: {
10: this.EventFiringEnabled = true;
11: }
12: }
2: {
3: public void DisableHandleEventFiring()
4: {
5: this.EventFiringEnabled = false;
6: }
7:
8: public void EnableHandleEventFiring()
9: {
10: this.EventFiringEnabled = true;
11: }
12: }
1: EventFiringHandler handler = new EventFiringHandler();
2: SPSite mysite = new SPSite("http://localhost/");
3: SPWeb web = mysite.OpenWeb();
4: SPList list = web.Lists["Tasks"];
5: SPListItem item = list.GetItemById(<taskItemID>);
6: Hashtable hashT = new Hashtable();
7: hashT.Add("Title","MyNewTitle");
8: handler.DisableHandleEventFiring();
9: SPWorkflowTask.AlterTask(item, hashT, true);
Hope this helps!
Updated Aug 27, 2020
Version 2.0SPDev_Support
Iron Contributor
Joined April 30, 2019
Microsoft SharePoint Blog
Welcome to the SharePoint Blog! Learn best practices, news, and trends directly from the SharePoint team.