I am interested in removing a Workflow from the list using the SP Object Model. How can I do this?
I am not having much luck with Google today!
OK. So here is the function I wrote that removes the Workflow from the list. Hope it helps someone :)
/// <summary>
/// Removes the workflow.
/// </summary>
/// <param name="workflowName">Name of the workflow.</param>
/// <param name="spList">The sp list.</param>
private static void RemoveWorkflow(string workflowName, SPList spList)
{
SPWorkflowAssociation spWorkflowAssociation =
spList.WorkflowAssociations.Cast<SPWorkflowAssociation>()
.FirstOrDefault(workflowAssociation => workflowAssociation.Name.Equals(workflowName));
if (spWorkflowAssociation != null)
{
spList.WorkflowAssociations.Remove(spWorkflowAssociation.Id);
}
spList.Update();
}