Search Wiki:
Using
Microsoft.TeamFoundation.VersionControl.Client.dll
Microsoft.TeamFoundation.WorkItemTracking.Client.dll

Sample Code
// create a new work item linked to an existing item in version control
static void CreateLinkedWorkItem(String teamProject, String workItemType)
{
    using (var tfs = TeamFoundationServerFactory.GetServer(_ServerUri))
    {
        var workItemStore = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
 
        var bugWorkItemType = workItemStore.Projects[teamProject].WorkItemTypes[workItemType];
        var workItem = bugWorkItemType.NewWorkItem();
 
        workItem.Fields["Title"].Value = "Test Bug";
 
        var versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
 
        var versionedItem = versionControl.GetItem(
            String.Format("$/{0}/BuildProcessTemplates/DefaultTemplate.xaml", teamProject),
            VersionSpec.Latest);
 
        var link = new ExternalLink(workItemStore.RegisteredLinkTypes["Source Code File"],
            versionedItem.ArtifactUri.ToString());
 
        workItem.Links.Add(link);
 
        workItem.Save();
    }
}

Notes
The registered link types for the default "Bug" work item type in TFS 2010 Beta 2 are:
  • Fixed in Changeset
  • Related Workitem
  • Result Attachment
  • Source Code File
  • Test Result
  • Workitem Hyperlink
Last edited Oct 27 2009 at 7:39 PM  by JimLamb, version 2
Updating...
Page view tracker