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!
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!
Try this code,
using(SPSite oSite = new SPSite("http://localhost/"))
{
using(SPWeb oWeb = oSite.OpenWeb())
{
SPList oList = oWeb.Lists["DocumentLib"];
SPWorkflowAssociation objWorkflowAssociation = oList.WorkflowAssociations.Cast<SPWorkflowAssociation>().FirstOrDefault(workflowAssociation => workflowAssociation.Name.Equals("Approval Workflow"));
if (objWorkflowAssociation != null)
{
oList.WorkflowAssociations.Remove(objWorkflowAssociation.Id);
}
oList.Update();
}
}
Its working on my end...
OK. So here is the function I wrote that removes the Workflow from the list. Hope it helps someone :)