Invoke SharePoint Workflow after EventReceiver

筅森魡賤 提交于 2019-12-08 18:58:27

You can use SPWorkFlowAssociation to run workflow that associate with List or Content Type . Example ( run workflow after adding item)

public override void ItemAdded(SPItemEventProperties properties)  
{  

    SPList parentList = properties.ListItem.ParentList;  
    SPWorkflowAssociation associationTemplate =         
      parentList.WorkflowAssociations.GetAssociationByName("Your 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);  

}  

More information about SPWorkflowAssociation Check the below link

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowassociation.aspx

SPListItem:

The "Synchronous" events (-ing ending like ItemAdd*ing*), are always executed before the workflow.

The "Asynchronous" events (-ed ending like ItemAdd*ed*), are always executed after the execution of the workflow.

So, you have to set the "Synchronization" property of the Elements.xml file equal to "Synchronous" and the workflow will always be executed after the event receiver.

ATTENTION: Events Added and Updated run asynchronously by default, so you have to do the change in the Elements.xml .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!