TFS API Part 52 – Getting Work Item History


Work Item History field isn’t just a Text field that shows all the changes in a specific work items, it’s a collection of Revision object. Each time you save a Work Item a new revision object is been create and represent the Work Item Latest values.

You can use the History to get previous values from Fields, Links and Attachments history.

In this post I’ll show how to get Work Item revision list and display the Fields of specific revision.


Download Demo Project

Step 1: Connecting To TFS And Getting Work Item Store

private void btnConnect_Click(object sender, RoutedEventArgs e)
    TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.NoProject, false);
    if (tpp.ShowDialog() != System.Windows.Forms.DialogResult.OK || tpp.SelectedTeamProjectCollection == null)
        btnFetch.IsEnabled = txtWitId.IsEnabled = false;

    tfs = tpp.SelectedTeamProjectCollection;
    store = new WorkItemStore(tfs, WorkItemStoreFlags.BypassRules);
    btnFetch.IsEnabled = txtWitId.IsEnabled = true;

Step 2: Getting Work Item History

Using WorkItemStore object you can get the work item, the work item object contains a Revisions collection that will allow you to navigate inside the work item history.

private void FetchWorkItemHistory()
    if (string.IsNullOrEmpty(txtWitId.Text)) return;

    if (!int.TryParse(txtWitId.Text, out _workitemId)) return;

    WorkItem wit = store.GetWorkItem(_workitemId);
    listRevs.ItemsSource = wit.Revisions;

You can also get the Work Item from specific Revision:

 WorkItem wit = store.GetWorkItem(_workitemId, rev.Index);

Download Demo Project

Add comment
facebook linkedin twitter email

Leave a Reply