Posts

Showing posts from October, 2018

TFS API: Get list of associated work item from work item of any type

I have been observing most of users reported and looking for a way to list out associated work item linked to parent work item. Generally, when we associated work item to another work item - it simply attach it as Link irrespective link type. We can achieve this using TFS Client Side Object model (API). Below is high level code snippet which will fetch all the links associated with work item. // Connect to the server and the store.  TfsTeamProjectCollection  teamProjectCollection = new TfsTeamProjectCollection(collectionUri); //Get the work item service workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore)); // Define a query that uses a variable for the type of work item.  string queryString = string.Format("Select * From WorkItems where Id = {0}",workItemId); // Create and run the query. Query query = new Query(workItemStore, queryString); WorkItemCollection results = query.RunQuery(); foreach(WorkItem wt in results) {