Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am building a web part in C# that will get all outstanding tasks in a sharepoint site collection. Using a CAML query I am returning all items from a task list where the status = "Not Started". From here I will need to link back to the workflow that started this task and from there get the content type of the workflow with all of the associated fields.

Does anyone have any sample code to do this? I've seen code to get to the task item list from a list item that had an associated workflow, but I haven't seen how to get the workflow from the task item list.

Thanks
Posted

You can use the Workflows[^] of the SPListItem. From there you can access the properties of SPWorkflow object necessary
 
Share this answer
 
Comments
swbo102 25-Apr-12 10:46am    
I've tried that, however it seems to always return a count of zero, even though I know a WF is associated to that specific task item.
Within the listItem object there is a field called "WorkflowInstanceID". Once you have that you can create a new SPWorkFlow object referencing that ID,

SPWorkflow workflowInstance = new SPWorkflow(oWeb, workflowInstanceId);


Once that is done you can go the list it is linked to via

SPList itemList = workflowInstance.ParentList;

From there I was able to get all I needed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900