SharePoint Development Blog

Nick Boumans
View my LinkedIn Profile Follow me on Twitter View my Profile on FaceBook View my projects on CodePlex View my presentations on SlideShare



Recent posts

Tags

Categories

Navigation

Pages

Archive

Blogroll

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Starting a Workflow from an Event Receiver

Out of the Box there are only a few options to start a (custom) workflow. E.g. when an item is created or changed. This means that there are a lot of situations that a workflow is fired where it is not needed (often a workflow only needs to be started if a field has a specific value). Therefore we can write an event receiver to time better when a workflow is started. Below you find the code to start a workflow from your event receiver.

[code:c#]
public override void ItemUpdated(SPItemEventProperties properties)  
{  
  if(YourCondition)  
  {  
    SPList parentList = properties.ListItem.ParentList;  
    SPWorkflowAssociation associationTemplate =         
      parentList.WorkflowAssociations.GetAssociationByName("Workflow Name",   
      new CultureInfo  
        (Convert.ToInt32(parentList.ParentWeb.RegionalSettings.LocaleId)));  
    SPSite siteCollection = properties.ListItem.ParentList.ParentWeb.Site;  
      siteCollection.WorkflowManager.StartWorkflow(properties.ListItem,  
      associationTemplate, String.Empty);  
  }  

[/code]

Posted: Apr 06 2008, 00:00 by Nick Boumans | Comments (4) RSS comment feed |
  • Currently 4.4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Workflow

Comments