You can easily get all the lists and document libraries that are associated with workflow in a SharePoint farm server. In this article, I am going to write C# code example to find and get all the workflow enabled lists using CSOM (Client-Object Model).
Get all workflow enabled lists in a given site
using Microsoft.SharePoint.Client;
//-------------------------------------
static void GetWorkFlowAssociatedLists()
{
string siteUrl = "http://sharepointsvr/sites/2/TestSite";
var siteCtx = new ClientContext(siteUrl);
siteCtx.Credentials = new NetworkCredential("SPAdministrator", "MyPassword");
Web site = siteCtx.Web;
siteCtx.Load(site.Lists, li => li.Include(w => w.WorkflowAssociations,
w => w.Title, w => w.BaseType));
siteCtx.ExecuteQuery();
// Getting all workflow associated lists
foreach (List list in site.Lists.Where(a => a.WorkflowAssociations.Count > 0
&& a.BaseType == BaseType.GenericList))
{
Console.WriteLine("List Name: " + list.Title);
Console.WriteLine("SubscribedWorkflows: " +
string.Join(";", list.WorkflowAssociations.Select(a => a.Name)));
Console.WriteLine("---------------------");
}
}
Get all workflow enabled document libraries in a given SharePoint site
using Microsoft.SharePoint.Client;
//-------------------------------------
static void GetWorkFlowAssociatedLibraries()
{
string siteUrl = "http://sharepointsvr/sites/2/TestSite";
var siteCtx = new ClientContext(siteUrl);
siteCtx.Credentials = new NetworkCredential("SPAdministrator", "MyPassword");
Web site = siteCtx.Web;
siteCtx.Load(site.Lists, li => li.Include(w => w.WorkflowAssociations,
w => w.Title, w => w.BaseType));
siteCtx.ExecuteQuery();
// Getting all workflow associated Document Libraries
foreach (List list in site.Lists.Where(a => a.WorkflowAssociations.Count > 0
&& a.BaseType == BaseType.DocumentLibrary))
{
Console.WriteLine("Libarary: " + list.Title);
Console.WriteLine("SubscribedWorkflows: " +
string.Join(";", list.WorkflowAssociations.Select(a => a.Name)));
Console.WriteLine("---------------------");
}
}
Advertisement