TL;DR; Shows how to use TFS API calls to list all files changed in a specific iteration, including querying work items and extracting changesets to a text file.

I was asked by a colleague to provide a list of all files that were changed under a particular iteration. Rather than delving into the data, I made a couple of API calls to TFS to output a text file with the list.
This is probably not the most efficient method and it is hard coded, but it does output the goods:
1Dim tfs As New TeamFoundationServer("http://testtfs01:8080")
2Dim store As WorkItemStore = tfs.GetService(GetType(WorkItemStore))
3Dim version As VersionControlServer = tfs.GetService(GetType(VersionControlServer))
4' Query for work items
5Dim query As String = "SELECT [System.Id], [System.Title] " _
6 & "FROM WorkItems " _
7 & "WHERE [System.TeamProject] = @Project " _
8 & "AND [System.IterationPath] UNDER @IterationPath " _
9 & "ORDER BY [System.Id]"
10Dim paramiters As New Hashtable
11paramiters.Add("Project", "TestProject1")
12paramiters.Add("IterationPath", "TestProject1TestIteration1")
13Dim y As WorkItemCollection = store.Query(query, paramiters)
14Console.WriteLine(String.Format("Found {0} work items", y.Count))
15' Query work items for attachments
16Dim wiats = From wi As WorkItem In y, l As Link In wi.Links Where l.BaseType = BaseLinkType.ExternalLink Select l, wi
17Console.WriteLine(String.Format("Loading {0} changesets...", wiats.Count))
18Dim ChangeSets As New List(Of Changeset)
19If Not wiats Is Nothing Then
20 Dim els = From i In wiats Where LinkingUtilities.DecodeUri(CType(i.l, ExternalLink).LinkedArtifactUri).ArtifactType = "Changeset"
21 For Each i In wiats
22 Dim el As ExternalLink = CType(i.l, ExternalLink)
23 Dim artifact As ArtifactId = LinkingUtilities.DecodeUri(el.LinkedArtifactUri)
24 If artifact.ArtifactType = "Changeset" Then
25 Dim cs As Changeset = version.ArtifactProvider.GetChangeset(New Uri(el.LinkedArtifactUri))
26 ChangeSets.Add(cs)
27 End If
28 Next
29 ' ------------------------------
30 Console.WriteLine(String.Format("{0} changesets loaded", ChangeSets.Count))
31 Dim files = From f In ChangeSets, c In f.Changes Select c.Item Distinct
32 Using x = System.IO.File.CreateText("c:Tempfiles.txt")
33 For Each f In files
34 x.WriteLine(f.ServerItem)
35 Next
36
37 End Using
38
39End If
40If Debugger.IsAttached Then
41 Console.ReadKey()
42End If
As you can see I have very bad naming and layout, but this is a one time use version of the code, so quick and dirty. If I am asked to do this again I would create a proper command line utility, or even a WPF interface to display the data prettily.
Technorati Tags: ALM WIT TFS Custom TFBS Version Control WPF TFS
If you've made it this far, it's worth connecting with our principal consultant and coach, Martin Hinshelwood, for a 30-minute 'ask me anything' call.
We partner with businesses across diverse industries, including finance, insurance, healthcare, pharmaceuticals, technology, engineering, transportation, hospitality, entertainment, legal, government, and military sectors.
CR2

Akaditi

Flowmaster (a Mentor Graphics Company)

Cognizant Microsoft Business Group (MBG)

Teleplan

Graham & Brown

YearUp.org

Bistech

Capita Secure Information Solutions Ltd

MacDonald Humfrey (Automation) Ltd.

Philips

Kongsberg Maritime

Lean SA
NIT A/S

Slicedbread

Boeing

Qualco

Milliman

Department of Work and Pensions (UK)

Nottingham County Council

Royal Air Force

Ghana Police Service

Washington Department of Enterprise Services

New Hampshire Supreme Court

Xceptor - Process and Data Automation

Illumina

Deliotte

Schlumberger
CR2

Freadom