I have a list called Students
on which there is a workflow running called StudentWorkflow
. I want to loop through all list items in Students
and retrieve their related W4InstanceId
from Workflow Tasks
list. How can I do that in C#?
Tried the following but it doesn’t display anything because it doesn’t go inside that second for loop:
using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["Students"]; foreach (SPListItem item in list.Items) { foreach (SPWorkflow wf in item.Workflows) //doesn't go inside { Console.WriteLine(item.ID + " " + wf.InstanceId); } } } }