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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | using Microsoft.SharePoint.Client; //------------------------------------- static void GetWorkFlowAssociatedLists() { 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | using Microsoft.SharePoint.Client; //------------------------------------- static void GetWorkFlowAssociatedLibraries() { 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