We are using SharePoint Foundation 2010.
We have created a workflow that checks the status of a task list.
If we associate the workflow with the list in the SharePoint UI it works fine.
We were wondering how we could automatically associate it, maybe in the feature receiver code that sets ut the site?
Browse to a list or library where you want to create SharePoint workflow. Select “Library” tab and click “Workflow Settings” on the ribbon. Then select “Add a workflow” from the dropdown menu.
Select “Workflows” on the left navigation pane. Then click on “List workflow” and select your list. Here you should add a new SharePoint Designer 2013 workflow to the list, enter its name and add a description.
SharePoint workflows are pre-programmed mini-applications that streamline and automate a wide variety of business processes. Workflows can range from collecting signatures, feedback, or approvals for a plan or document, to tracking the current status of a routine procedure.
// 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With