In this article, I’d be articulating on how to retrieve list of installed workflows in SharePoint 2013 Office 365 site using Client Side Object Model (CSOM). Just to give a background the workflow framework in SP 2013 has undergone a major revamp, there are new WorkflowServicesManager and WorkflowDeploymentService objects, we’d also be leveraging the new APIs accordingly to retrieve
Create a console application and name it as ‘RetrieveInstalledWorkflows’.
Add references to the following dll’s.
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
Microsoft.SharePoint.Client.WorkflowServices.dll
Import the following namespaces
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.WorkflowServices;
using Microsoft.SharePoint.Client.WorkflowServices;
using Microsoft.SharePoint.Client.Workflow;
Create a static method by name ‘RetrieveInstalledWorkflows’ and implement the following snippet of code.
public static void RetrieveInstalledWorkflows()
{
Uri oUri = new Uri(“https://yoursite.sharepoint.com”);
Office365ClaimsHelper claimsHelper = new Office365ClaimsHelper(oUri, “userid@yoursiter.onmicrosoft.com”, “your password”);
using (ClientContext oClientContext = new ClientContext(oUri))
{
oClientContext.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
//Get the instance of Workflow Services Manager
WorkflowServicesManager oWorkflowServicesManager = new WorkflowServicesManager(oClientContext,oClientContext.Web);
//Hook to WorkflowDeploymentService
WorkflowDeploymentService oWorkflowDeploymentService = oWorkflowServicesManager.GetWorkflowDeploymentService();
//Fetch all the installed workflows
var oWorkflowDefinitionCollection = oWorkflowDeploymentService.EnumerateDefinitions(true);
oClientContext.Load(oWorkflowDefinitionCollection);
oClientContext.ExecuteQuery();
foreach(var oWorkflowDefinition in oWorkflowDefinitionCollection)
{
Console.WriteLine(“Workflow”+oWorkflowDefinition.DisplayName);
}
Console.ReadLine();
}
}
To know more about Office365ClaimsHelper class, please refer to Wictor Wilen’s article on active authentication
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }