The World of Workflow Analysis and Reporting :)

A piece of code to see workflows and its instances

int WorkflowCount = 0;
Console.WriteLine("Start:" + DateTime.Now.TimeOfDay.ToString());
using (var site = new SPSite(http://sitecollection)) // Change here with site collection url
using (var web = site.AllWebs["/web/"]) // change here with web site url of use RootWeb
var manager = site.WorkflowManager;
foreach (SPList list in web.Lists)
if (!list.Hidden || list.BaseTemplate == SPListTemplateType.XMLForm || list.BaseTemplate == SPListTemplateType.DocumentLibrary)
foreach (SPListItem item in list.Items)
foreach (SPWorkflow workflow in item.Workflows)
if ((workflow.InternalState & SPWorkflowState.Running) != SPWorkflowState.Running)
WorkflowCount += 1;
} } } } } } }
Console.WriteLine("Start:" + DateTime.Now.TimeOfDay.ToString());


It took me over 1 minute to find the number of instances.  Not good if you want to show it to a Workflow Admin.  Another reason for slowness is my current development machine (P4 with 3 GB RAM is not a good one).  You also have other properties available using Workflow.Parent which is a list item.  One you have it then you can do whatever you want.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s