1

我有一个关于SharePoint工作流程和事件接收器的问题。我收到了一个设置元素元数据的事件接收器。之后,我使用工作流将项目元数据复制到列表中。不幸的是,工作流程不会复制事件接收器设置的元数据。我想是因为它是在事件接收器之前执行的。是否有可能更改订单,以便工作流将在事件接收器之后执行?接收者以同步方式绑定到ItemAdded和ItemUpdated Events。在EventReceiver后调用SharePoint工作流程

谢谢你的帮助! Patrick

回答

2

您可以使用SPWorkFlowAssociation运行与List或Content Type关联的工作流。约SPWorkflowAssociation 例(添加项目后运行的工作流程)

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); 

} 

更多信息,请下面的链接

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

0

SPListItem:

“同步” 事件(-ing像ItemAdd结束* ing *),始终在工作流程之前执行。

“异步”事件(以ItemAdd * ed *结尾)始终在执行工作流程后执行。

因此,您必须将Elements.xml文件的“同步”属性设置为“同步”,并且工作流将始终在事件接收器之后执行。

注意事项:添加和更新的事件默认情况下是异步运行的,因此您必须在Elements.xml中进行更改。