Get the item a SharePoint workflow task is associated with

This is handy. SharePoint helpfully populates the meta data with the GUID of the list and the ID of the item a WF instance is associated with. These are stored in "ows_WorkflowListId" and "ows_WorkflowItemId" fields on the task list item.

 An example of using this is from an InfoPath form in the form load code behind.

1SPListItem currentListItem = SPContext.Current.ListItem; if (currentListItem != null) {   object associatedWfListId = currentListItem\["ows\_WorkflowListId"\];   object associatedWfItemId = currentListItem\["ows\_WorkflowItemId"\];     if (associatedWfItemId != null && associatedWfListId != null)   {     SPListItem item = web.Lists.GetList(new Guid(associatedWfListId.ToString()), false).GetItemById(int.Parse(associatedWfItemId.ToString()));     // THE ABOVE ITEM IS THE ASSOCIATED LIST ITEM   } }