Skip to content

Instantly share code, notes, and snippets.

@vman
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vman/01bd9bc3b5161241005c to your computer and use it in GitHub Desktop.
Save vman/01bd9bc3b5161241005c to your computer and use it in GitHub Desktop.
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Workflow;
using Microsoft.SharePoint.Client.WorkflowServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
namespace CSOMWorkflow
{
class Program
{
static void Main(string[] args)
{
//Replace the following values according to your configuration.
//Site details
string siteUrl = "https://mytenant.sharepoint.com/sites/test";
string userName = "user@mytenant.onmicrosoft.com";
string password = "password";
//Name of the SharePoint 2010 Workflow to start.
string workflowName = "SP2010SiteWF";
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();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment