How do SharePoint workflows and SharePoint event handlers differ?
Learn what the differences are between a SharePoint event handler (or event receiver) and a SharePoint workflow, and when it is appropriate to use one or the other.
A SharePoint event handler or event receiver is a piece of code that runs when an event, such as the adding, deleting, or changing of a SharePoint list item or document, takes place.
They react to changes just like a SharePoint workflow can react to those same changes made to an item.
SharePoint event handlers vs. SharePoint workflows
The main differences between SharePoint event handlers and SharePoint workflows are:
SharePoint event handlers are automatically initiated, while SharePoint workflows can be initiated either automatically or manually.
A SharePoint event handler always responds to an event that has taken or is taking place on an item, while a SharePoint workflow does not necessarily have to react to an event that is taking place. While it can react to an item being created or changed, you can also manually start a workflow after an item has been created.
SharePoint event handlers have no user interface, so users cannot interact with event handlers. On the other hand, you can create either ASP.NET or InfoPath forms to provide user interactivity with SharePoint workflows. And you can add even more interactivity by using SharePoint Tasks lists along with the workflow.
SharePoint event handlers run for a short period of time (generally seconds), while SharePoint workflows may run for a much longer time period (days, months, or even years).
Since SharePoint workflows are hydrated and dehydrated, they can “survive” server reboots, while SharePoint event handlers cannot.
When to choose what?
When deciding whether to go with a SharePoint event handler or a SharePoint workflow for a piece of functionality or business logic that you require, consider the 5 points mentioned above.
Go with a SharePoint event handler if the tasks you want to perform are directly related to the user taking a particular action on an item (such as adding, editing, or deleting it), you do not require the user to interact with your code, and whatever the event handler has to do is of a short duration.
Go with a SharePoint workflow if the tasks you want to perform are not directly related to the user taking a particular action on an item, you require interaction between the user and your code, your code may run for a long duration, and should live through server reboots.
- 3 Ways to create workflows for WSS 3.0 and Office SharePoint 2007
- Defining and using workflows (BPM) in EDM
- Using a GUID to look up a SharePoint list item instead of an ID