Stop orCancel aWorkflow programaically

SPSecurity.RunWithElevatedPrivileges(delegate() { 
                using (SPSite site = new SPSite(SPContext.Current.Site.ID)) 
                { 
                    using (SPWeb web = site.OpenWeb()) 
                    {  
                        SPWorkflowManager manager = site.WorkflowManager; 
                        //SPList currentList = web.Lists["Implementation Details"]; 
                        //int id = Convert.ToInt32(Request.Params["ID"]); 
                        SPListItem lstimpitem = GetListDetails("Implementation Details", Request.Params["ID"].ToString()); //currentList.GetItemById(Convert.ToInt32(Request.Params["ID"])); 
                    
                        //SPListItem item = web.Lists[properties.ListTitle].GetItemById(properties.ListItemId);  
                         
                        foreach (SPWorkflow workflow in manager.GetItemActiveWorkflows(lstimpitem)) 
                        {  
                            foreach (SPWorkflowTask t in workflow.Tasks)  
                            { 
                                t.Web.AllowUnsafeUpdates = true; 
                                t["Status"] = "Canceled"; 
                                 
                                t.Update(); 
                                SPWorkflowManager.CancelWorkflow(workflow); 
                                t.Web.AllowUnsafeUpdates =false; 
                                string message = "Workflow is cancelled successfully"; //  + mailUsers.TrimEnd(',') + "\\\""; 
                                Context.Response.Write("<script type='text/javascript'>alert('" + message + "');window.frameElement.commitPopup();</script>"); 
                                Context.Response.Flush(); 
                                Context.Response.End(); 
                                 
                            } 
                           
                             
                        }  
                    }  
                }  
            }); 

Comments

Popular posts from this blog

SP People Picker Validation

Create multiple web parts in one SPFx Solution

JQgrid Auto Complete functionality for a textbox using Jquerry