Click here to Skip to main content
12,697,620 members (27,185 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


10 bookmarked

TFS SDK: Work Item History Visualizer using TFS API

, 22 Aug 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
  If you track your project tasks against work items, you would know the importance of Work Item History. This is one way for you to reflect on who did what and when, some organizations use it for auditing purposes as well.

If you track your project tasks against work items, you would know the importance of Work Item History. This is one way for you to reflect on who did what and when, some organizations use it for auditing purposes as well. Using the WorkItemStore service it is possible to get the work item revisions, now depending on how creative you are, you can plot the data and visualize the changes as you like.

In this blog post I'll be showing you,

  • How to get the work item history programmatically using TFS API
  • Display the work item history programmatically in a data grid

A screen shot of what we are after,


1. Get the Work Item Details Programmatically using TFS API

I’ll start simple. Pass a work item id to get the work item details.

public WorkItem GetWorkItemDetails(int id)
            var tfs =
                    new Uri("https://tfs2010:8080/defaultcollection"));
            var service = tfs.GetService<WorkItemStore>();

            return service.GetWorkItem(id);

The above code will return the WorkItem object, we will be interested in the property “Revisions” - Gets a RevisionCollection object that represents a collection of valid revision numbers for this work item.

2. Get the Work Item Revision ‘History’ Programmatically using TFS API

Now it is very important to understand that the revision history can only be retrieved for work item fields available in the collection WorkItem.Fields, so if you used the below code to get the workitem revision history you will NOT see the history but end up reloading the current workitem object again and again.

// Returns a work item object
var wi = GetWorkItemDetails(299);

// This will NOT give you work item history
// will only loop through revisions and
// actually not load the work item history
// but will load the latest work item revision
// again and again
foreach (Revision revision in wi.Revisions)

Let’s have a look at the Fields property in the WorkItem object,

// Work Item fields for which we can get history
foreach (Field field in wi.Fields)
    Debug.Write(String.Format("{0}{1}", field.Name, Environment.NewLine));


Authorized Date
Changed By
Backlog Priority
Integration Build
Description HTML
Iteration Path
Iteration ID
Assigned To
Work Item Type
Acceptance Criteria
Created Date
Created By
Business Value
External Link Count
Related Link Count
Team Project
Hyperlink Count
Attached File Count
Node Name
Area Path
Revised Date
Changed Date
Area ID
Authorized As

So, it is safe to use the below code to get the work item history using the TFS API programmatically,

// Returns a work item object
var wi = GetWorkItemDetails(299);

// Get All work item revisions
foreach (Revision revision in wi.Revisions)
    // Get value of fields in the work item revision
    foreach (Field field in wi.Fields)

Lets see the output now,

Revision[0]: Title - This is a test PBI 1
Revision[0]: State - New
Revision[0]: Authorized Date - 08/08/2011 22:18:24
Revision[0]: Watermark - 1
Revision[0]: Rev - 1
Revision[0]: Changed By -
Revision[0]: Backlog Priority - 1000
Revision[0]: Integration Build - 
Revision[0]: Description HTML - As a &lt;type of user&gt; I want &lt;some goal&gt; so that &lt;some reason&gt;
Revision[0]: Reason - New backlog item
Revision[0]: Iteration Path - Temp_UK_1
Revision[0]: Iteration ID - 161
Revision[0]: Assigned To -
Revision[0]: Work Item Type - Product Backlog Item
Revision[0]: Effort - 100
Revision[0]: Acceptance Criteria - 
Revision[0]: Created Date - 08/08/2011 22:18:24
Revision[0]: Created By -
Revision[0]: Business Value - 1000
Revision[0]: Description - 
Revision[0]: History - 
Revision[0]: External Link Count - 0
Revision[0]: Related Link Count - 0
Revision[0]: Team Project - Temp_UK_1
Revision[0]: Hyperlink Count - 0
Revision[0]: Attached File Count - 0
Revision[0]: Node Name - Functional
Revision[0]: Area Path - Temp_UK_1\Functional
Revision[0]: Revised Date - 08/08/2011 22:18:42
Revision[0]: Changed Date - 08/08/2011 22:18:24
Revision[0]: ID - 299
Revision[0]: Area ID - 165
Revision[0]: Authorized As -
Revision[1]: Title - This is a test PBI 1
Revision[1]: State - Approved
Revision[1]: Changed Date - 08/08/2011 22:18:42
Revision[2]: Changed Date - 08/08/2011 22:18:50
<a href="[3">…
Revision[6]: Title - This is a test PBI 1 - 2 - 3
Revision[6]: State - Done
Revision[6]: Authorized Date - 14/08/2011 23:00:49
Revision[6]: Changed By -
Revision[6]: Backlog Priority - 1000
Revision[6]: Integration Build - 
Revision[6]: Description HTML - <P>Whats up ? Hello World</P>

3. Putting everything together

Lets get the work item history and display the results through a datagrid

        /// <span class="code-SummaryComment"><summary>


4. Next Step - Visualize work item history

Let’s take this a step forward and do some visualization, I'll keep it simple by printing the results to the output window, but you can take this a step forward by printing the output to some visually attractive controls.

        /// <span class="code-SummaryComment"><summary>



Work Item: 299
Comparing Revision 1 to 2 
Changed By '' On '08/08/2011 22:18:24'
[State]: 'New' => 'Approved' 
[Reason]: 'New backlog item' => 'Approved by the Product Owner' 
Comparing Revision 2 to 3 
Changed By '' On '08/08/2011 22:18:42'
[State]: 'Approved' => 'Committed' 
[Reason]: 'Approved by the Product Owner' => 'Commitment made by the team' 
Comparing Revision 3 to 4 
Changed By '' On '08/08/2011 22:18:50'
[State]: 'Committed' => 'Done' 
[Reason]: 'Commitment made by the team' => 'Work finished' 
Comparing Revision 4 to 5 
Changed By '' On '08/08/2011 22:18:57'
Comparing Revision 5 to 6 
Changed By '' On '14/08/2011 22:53:43'
[Title]: 'This is a test PBI 1' => 'This is a test PBI 1 - 2 - 3' 
Comparing Revision 6 to 7 
Changed By '' On '14/08/2011 23:00:41'

Thoughts, Questions, Feedback, Suggestions, please feel free to add a comment.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Avanade
United Kingdom United Kingdom
Solution Developer - C# .NET, ALM

Tarun Arora is a Microsoft Certified professional developer for Enterprise Applications. He has over 5 years of experience developing 'Energy Trading & Risk Management' solutions using Microsoft Technologies. Tarun has great passion for technology and travel (not necessarily in the same order)!

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Wes Grant31-Aug-13 5:15
memberWes Grant31-Aug-13 5:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 22 Aug 2011
Article Copyright 2011 by Tarun_Arora
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid