Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add SharePoint workflow to a list programmatically

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?

like image 588
Shiraz Bhaiji Avatar asked Aug 12 '10 07:08

Shiraz Bhaiji


People also ask

How do I add a workflow to a SharePoint list?

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.

How do I add a workflow to a list in SharePoint 2013?

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.

What is SharePoint list workflow?

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 Answers

// 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;
like image 169
Marek Grzenkowicz Avatar answered Sep 27 '22 22:09

Marek Grzenkowicz