New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Create Parent-Child Link between two TFS Work Items

104 Views
Copy Code Show/Hide Line Numbers
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();
        }
    }
}
by Jim Lamb
  April 13, 2010 @ 8:06am
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate