Monday, July 9, 2012

Delete all related tasks when workflow complete in sharepoint

When your workflow finished or terminated, you might see some tasks still remain in the task list. Do you want to get rid of them?

Following code help you to remove all tasks remain after workflow complete.


using (var spweb = workflowProperties.Web)
                {
                    spweb.AllowUnsafeUpdates = true;
                    var list = workflowProperties.Item.Tasks.Count;
                    while (list>0)
                    {
                        workflowProperties.Item.Tasks[0].Delete();
                        list = workflowProperties.Item.Tasks.Count;
                    }
                    spweb.AllowUnsafeUpdates = false;
                }

No comments:

Post a Comment