Changing the SPWorkflowAssociation.AutoCleanupDays property


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!


Comments (6)

  1. Janne says:

    Hi

    Is it possible create small tool ? I am not developer so could not use this code 🙁

  2. Mario says:

    Please check blogs.tamtam.nl/…/SharePoint+Worflow+History+Lost.aspx

    There is already prepared tool, just download and run

  3. Stefan Bauer says:

    Great information. Had the request by a customer today.

    /greetings

    Stefan

  4. fgsdgfdg says:

    fgsdfgfgsdddddddddddddddddddddgretretre

  5. Keith Oswalt says:

    I know this is an old post, but has anyone seen an adverse effect to making this change?  I have a customer who wants to set this selectively to maybe up to 7 years.  Just wondering what I am not thinking of that may make that a bad idea.  It would not be for every workflow, but is there still a reason to NOT do it for any workflow?  Thanks.

Skip to main content