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

Popular posts from this blog

javascript to get the all site user in sharepoint 2010 (Getting all Site users using Client Object Model)

SharePoint 2010: JavaScript Code To Check if user exists in a group (ECMA)

Disable all day event, Recurrence,Workspace Fields in Calendar list