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中進行更改。