Auto associate workflow with list programmatically (sharepoint2010)
private void AssociateWorkflow(SPWeb web)
{
SPList assocList = web.Lists["TestWFList"];
SPList wflHistoryList = web.Lists["Workflow History"];
SPList wflTaskList = web.Lists["Tasks"];
SPWorkflowTemplate wflTemplate = web.WorkflowTemplates.GetTemplateByName("TestWF", System.Globalization.CultureInfo.CurrentCulture);
SPWorkflowAssociation wflAss = SPWorkflowAssociation.CreateListAssociation(wflTemplate, "Custom_Approval_WorkFlow - Workflow11", wflTaskList, wflHistoryList);
wflAss.AutoStartChange = false;
wflAss.AutoStartCreate = true;
wflAss.AllowManual = true;
web.AllowUnsafeUpdates = true;
if (assocList.WorkflowAssociations.GetAssociationByName(wflAss.Name,System.Globalization.CultureInfo.CurrentCulture) == null)
{
assocList.WorkflowAssociations.Add(wflAss);
}
else
{
assocList.WorkflowAssociations.Update(wflAss);
}
assocList.Update();
web.AllowUnsafeUpdates = false;
}you need to call this code in feature activated event in event receiver.
Comments
Post a Comment