Language: C#
Create Parent-Child Link between two TFS Work Items
using System; using Microsoft.TeamFoundation.Client; using Microsoft.TeamFoundation.WorkItemTracking.Client; class Program { /// <summary> /// Create a parent-child link between two work items in a TFS team project collection /// </summary> /// <param name="args"></param> static void Main(string[] args) { // use a reference to the project collection containing the work items using (var projectCollection = TfsTeamProjectCollectionFactory. GetTeamProjectCollection(new Uri("http://tfServerName:8080/tfs/collectionName"))) { // get the work item store for the collection var workItemStore = projectCollection.GetService<WorkItemStore>(); // get the link type for hierarchical relationships var linkType = workItemStore.WorkItemLinkTypes[CoreLinkTypeReferenceNames.Hierarchy]; // fetch the work items to be linked var parentWorkItem = workItemStore.GetWorkItem(1); var childWorkItem = workItemStore.GetWorkItem(2); // add a new link to the parent relating the child and save it parentWorkItem.Links.Add(new WorkItemLink(linkType.ForwardEnd, childWorkItem.Id)); parentWorkItem.Save(); } } }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

