Today i was trying to figure out how to set the option 'Start this workflow to approve publishing a major version of an item' on my SharePoint list workflow. After some research I found out that the way to go is this:
-
Cast the SPList object to an SPDocumentLibrary
-
Attach the workflow to the document library object
-
Set the DefaultContentApprovalWorkflowId
-
Update the list
The code will be something like this:
// list is an SPList object, workflowAssociation is an SPWorkflowAssociation object
SPDocumentLibrary docLib = (SPDocumentLibrary)list; // cast
docLib.WorkflowAssociations.Add(workflowAssociation); // attach
docLib.DefaultContentApprovalWorkflowId = workflowAssociation.Id; // set property
list.Update(); // save the list
7360d76b-24cb-43e4-a5c4-bcc99ce4b4f9|1|5.0