Tuesday, November 27, 2012

How to cancel running workflows in a sharepoint list using server code.

                    web = site.OpenWeb();
                    SPWorkflowManager manager = site.WorkflowManager;
                    SPList list = web.Lists["mySPList"];
                    SPQuery q = new SPQuery();
                    q.Query = "<Where><Eq><FieldRef Name='EmpId'/><Value Type='Number'>" +Convert.ToInt32(lblEmpId.Text) + "</Value></Eq></Where>";
                   SPListItemCollection collection = list.GetItems(q);
                    foreach (SPListItem item in collection)
      foreach (SPWorkflow workflow in manager.GetItemActiveWorkflows(item))
                            foreach (SPWorkflowTask t in workflow.Tasks)
                                t["Status"] = "Canceled";

No comments:

Post a Comment

Featured Post

Azure Scripts

 Azure Scripts: Azure > Storage account > File shares > SMB File share To connect to this Azure file share from Windows, run the Po...

Popular posts