You don’t want new instances of your workflow association, so here is the code snippet & it’s API description.

You have installed the new version of a workflow and you don’t want to create the instances of previous association or because of other reasons you don’t want to end users to create new instances of workflow ( Workflow Association). You can remove workflow from UI through UI by selecting “Remove Workflows” under “settings” . Here is the screen shot :-

 image

But if you would like to achieve the SharePoint Object Model then “SPworkflowAssosiation” instance contain the running workflow values in SharePoint. Firstly, you have to traverse the list’s workflow associations and keep SPworkflowAssosiation in SPWorkflowAssosiation array after setting the enabled property of object false. Update the list in separate for loop.

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Text;
    5: using Microsoft.SharePoint;
    6: using Microsoft.SharePoint.Workflow;
    7:  
    8: namespace WorkflowAssosiation
    9: {
   10:     class Program
   11:     {
   12:         static void Main(string[] args)
   13:         {
   14:  
   15:             using (SPSite site = new SPSite("https://blre3r15-5:3000/sites/TestSite"))
   16:             {
   17:                 using (SPWeb web = site.RootWeb)
   18:                 {
   19:                     SPListCollection lists = web.Lists;
   20:                     SPWorkflowAssociation[] myUpdate = new  SPWorkflowAssociation[15];;
   21:                     int cwaUpdate = 0;
   22:                     string ListId = string.Empty;
   23:                     foreach (SPList list in lists)
   24:                     {
   25:                         SPWorkflowAssociationCollection collection = list.WorkflowAssociations;
   26:                         foreach (SPWorkflowAssociation assosiation in collection)
   27:                         {
   28:                                                
   29:                             //SPWorkflowAssociation assosiation = collection.GetAssociationByBaseID(guid);
   30:                             if (assosiation != null)
   31:                             {
   32:                                 
   33:                                 Console.WriteLine(assosiation.Enabled.ToString());
   34:                                 
   35:                                 assosiation.Enabled = false;
   36:                                 myUpdate[cwaUpdate++] = assosiation;
   37:                                 Console.WriteLine(assosiation.Enabled.ToString());
   38:                                 ListId = list.ID.ToString();
   39:                             }
   40:                             }
   41:                         
   42:                     }
   43:                     if (ListId != null || ListId == string.Empty)
   44:                     {
   45:                         System.Guid guid2 = new Guid(ListId);
   46:                         SPList newList = web.Lists[guid2];
   47:                         for (int i = 0; i < cwaUpdate; i++)
   48:                         {
   49:                             newList.UpdateWorkflowAssociation(myUpdate[i]);
   50:                         }
   51:                     }
   52:                 }
   53:                 Console.WriteLine("Press any key to continue....");
   54:                 Console.Read();
   55:             }
   56:           
   57:         }
   58:     }
   59: }