Sunday, 24 July 2016

Start A workflow programtically in sharepoint

private void StartWorkflowInstance()
        {
           
       
            try
            {

                //SPWorkflowManager objWorkflowManager = listItem.Web.Site.WorkflowManager;
                SPWorkflowManager objWorkflowManager = SPContext.Current.Web.Site.WorkflowManager;
                SPList _list = SPContext.Current.Web.Lists["listname"];
                SPListItem _listItem = _list.GetItemById(listItem.ID);

                if (objWorkflowManager.GetItemWorkflows(_listItem).Count == 0)
                {
                    SPWorkflowAssociationCollection objWorkflowAssociationCollection = _listItem.ParentList.WorkflowAssociations;

                    foreach (SPWorkflowAssociation objWorkflowAssociation in objWorkflowAssociationCollection)
                    {
                        if (objWorkflowAssociation.Name == rbClassificationOfOutgoingDocument.SelectedItem.Text  + " "+ ProcessModelOneConstants.FullAdHocWrokflowName)
                        {
                            SPWorkflow activeWorkflow = objWorkflowManager.StartWorkflow(_listItem, objWorkflowAssociation, objWorkflowAssociation.AssociationData, true);
                            SPUser initiator = activeWorkflow.AuthorUser;
                            string initName = initiator.Name;
                        }
                    }
                }
            }
            catch (Exception exception)
            {

            }
        }

No comments:

Post a Comment