By default the SPWorkflowAssociation.AutoCleanupDays property value is set to ‘60’ days, to set this property we need to call the SPList.UpdateWorkflowAssociation(SPWorkflowAssociation) function, SPWeb.Update() won’t work here.

 

   1: SPSite site = new SPSite("<http://nishandv3:100/sites/DevSite/>");
   2: SPWeb web = site.OpenWeb();
   3: SPWorkflowTemplateCollection collection = web.WorkflowTemplates;
   4: SPList list = web.Lists["Shared Documents"];
   5: SPWorkflowAssociation _asso = null;
   6: foreach (SPWorkflowAssociation asso in list.WorkflowAssociations)
   7: {
   8: if (asso.Name == "Approval")
   9: {
  10: asso.AutoCleanupDays = 100;
  11: _asso = asso;
  12: }
  13: }
  14: list.UpdateWorkflowAssociation(_asso); 

 

Hope this works for you!