以编程方式将SharePoint工作流添加到列表中

Shi*_*iji 8 sharepoint workflow sharepoint-2010

我们正在使用SharePoint Foundation 2010.

我们创建了一个工作流,用于检查任务列表的状态.

如果我们将工作流与SharePoint UI中的列表相关联,则可以正常工作.

我们想知道我们如何自动关联它,也许是在设置网站的功能接收器代码中?

Mar*_*icz 10

// 1. create an instance of the SPWorkflowAssociation class
SPWorkflowAssociation workflowAssociation =
  SPWorkflowAssociation.CreateListAssociation(workflowTemplate, associationName, taskList, historyList);

// 2. set start options
workflowAssociation.AllowManual = true;
workflowAssociation.AutoStartChange = false;
workflowAssociation.AutoStartCreate = false;

// 3. set additional association options (if any)
workflowAssociation.AssociationData = associationData;

// 4. add workflow association to the list
list.WorkflowAssociations.Add(workflowAssociation);

// 5. enable workflow association, so it is displayed in the user interface
workflowAssociation.Enabled = true;
Run Code Online (Sandbox Code Playgroud)