public static bool TriggerWorkflow(string SiteURL, string WorkflowName)
        {
            bool status = false;

            try
            {
                string siteUrl  = SiteURL;
                string userName = "******";
                string password = "******";

                //Name of the SharePoint 2010 Workflow to start.
                string workflowName = WorkflowName;

                using (ClientContext clientContext = new ClientContext(siteUrl))
                {
                    SecureString securePassword = new SecureString();

                    foreach (char c in password.ToCharArray())
                    {
                        securePassword.AppendChar(c);
                    }

                    clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                    Web web = clientContext.Web;

                    //Workflow Services Manager which will handle all the workflow interaction.
                    WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, web);

                    //Will return all Workflow Associations which are running on the SharePoint 2010 Engine
                    WorkflowAssociationCollection wfAssociations = web.WorkflowAssociations;

                    //Get the required Workflow Association
                    WorkflowAssociation wfAssociation = wfAssociations.GetByName(workflowName);

                    clientContext.Load(wfAssociation);

                    clientContext.ExecuteQuery();

                    //Get the instance of the Interop Service which will be used to create an instance of the Workflow
                    InteropService workflowInteropService = wfServicesManager.GetWorkflowInteropService();

                    var initiationData = new Dictionary <string, object>();

                    //Start the Workflow
                    ClientResult <Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), Guid.Empty, Guid.Empty, initiationData);

                    clientContext.ExecuteQuery();
                    status = true;
                }
            }
            catch (Exception ex)
            {
                status = false;
                throw;
            }
            return(status);
        }
Esempio n. 2
0
        private static void StartWFOnPremise()
        {
            //Site Details
            string siteUrl  = "http://rdits-sp13-dev2/sites/gs/";
            string userName = "******";
            string password = "******";

            //Name of the SharePoint2010 List Workflow
            string workflowName = "Approbation 2010";

            //Name of the List to which the Workflow is Associated
            string targetListName = "cadeaux";

            //Guid of the List to which the Workflow is Associated
            Guid targetListGUID = new Guid("cb1ef47f-6fbf-4119-97c5-057006db6a13");

            //Guid of the ListItem on which to start the Workflow
            //Guid targetItemGUID = new Guid("B10F6CF0-86F2-4F6D-B982-BBF9FB38897E");
            Guid targetItemGUID = new Guid("31D3B801-5C0C-4758-8AE0-3BF23BD6E430");

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                //SecureString securePassword = new SecureString();

                //foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);

                //clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                Web web = clientContext.Web;

                List     list = web.Lists.GetByTitle(targetListName);
                ListItem item = list.GetItemById(19);

                clientContext.Load(item);
                clientContext.ExecuteQuery();

                string guid = item["GUID"].ToString();

                //Workflow Services Manager which will handle all the workflow interaction.
                WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, web);

                //Will return all Workflow Associations which are running on the SharePoint 2010 Engine
                WorkflowAssociationCollection wfAssociations = web.Lists.GetByTitle(targetListName).WorkflowAssociations;

                //Get the required Workflow Association
                WorkflowAssociation wfAssociation = wfAssociations.GetByName(workflowName);

                clientContext.Load(wfAssociation);

                clientContext.ExecuteQuery();

                //Get the instance of the Interop Service which will be used to create an instance of the Workflow
                InteropService workflowInteropService = wfServicesManager.GetWorkflowInteropService();

                var initiationData = new Dictionary <string, object>();
                initiationData.Add("DisplayName", "Julien Bessiere");
                initiationData.Add("AccountId", "i:0#.f|membership|[email protected]");
                initiationData.Add("AccountType", "User");

                //Start the Workflow
                ClientResult <Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), targetListGUID, Guid.Parse(guid), initiationData);

                try
                {
                    clientContext.ExecuteQuery();
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }
Esempio n. 3
0
        private static void StartWFOnLine()
        {
            //Site Details
            string siteUrl  = "https://jbes.sharepoint.com/sites/gosport";
            string userName = "******";
            string password = "******";

            //Name of the SharePoint2010 List Workflow
            string workflowName = "Approbation 2010";

            //Name of the List to which the Workflow is Associated
            string targetListName = "Liste des demandes";

            //Guid of the List to which the Workflow is Associated
            Guid targetListGUID = new Guid("cbe00484-055e-4dca-ade1-863ef7b202ba");

            //Guid of the ListItem on which to start the Workflow
            //Guid targetItemGUID = new Guid("");

            using (ClientContext clientContext = new ClientContext(siteUrl))
            {
                SecureString securePassword = new SecureString();

                foreach (char c in password.ToCharArray())
                {
                    securePassword.AppendChar(c);
                }

                clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                Web web = clientContext.Web;

                List     list = web.Lists.GetByTitle(targetListName);
                ListItem item = list.GetItemById(1);

                clientContext.Load(item);
                clientContext.ExecuteQuery();

                string guid = item["GUID"].ToString();

                //Workflow Services Manager which will handle all the workflow interaction.
                WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, web);

                //Will return all Workflow Associations which are running on the SharePoint 2010 Engine
                WorkflowAssociationCollection wfAssociations = list.WorkflowAssociations;

                //Get the required Workflow Association
                WorkflowAssociation wfAssociation = wfAssociations.GetByName(workflowName);

                clientContext.Load(wfAssociation);

                clientContext.ExecuteQuery();

                //Get the instance of the Interop Service which will be used to create an instance of the Workflow
                InteropService workflowInteropService = wfServicesManager.GetWorkflowInteropService();

                var initiationData = new Dictionary <string, object>();

                //Start the Workflow
                ClientResult <Guid> resultGuid = workflowInteropService.StartWorkflow(wfAssociation.Name, new Guid(), targetListGUID, Guid.Parse(guid), initiationData);

                clientContext.ExecuteQuery();
            }
        }