tags:

views:

252

answers:

4

I am writing a tool that needs to access all the revisions of a TFS workitem template.

The Workitem has a Revisons collection, and Rev property that returns the number of revisions.

When I try and do a foreach through the collection, even though it contains 6 "entries" in my test workitem, the collection is empty.

To work around this I am using the GetWorkItem(WorkItemID, RevisionID), incrementing the revision ID in a for loop to get the revisions. It seems crazy taht I have to do this and there collection that doesn't contain what it is supposed to.

Am I missing something here, or is this simply a bug in the TFS client API.

A: 

Depending on how your retrieving the work item it may only be partially loaded. Try calling the Open method on the work item before accessing the Revisions collection.

William D. Bartholomew
Calling open doesn't populate the collection.
Bruce McLeod
A: 

After much digging, it is quite clear to me now that if you want to get all the revisions of a work item, you must explicitly load the revision(2) that you want, and this makes the revisions collection pretty much useless.

Bruce McLeod
A: 

Hi,

I'm using the Microsoft.TeamFoundation.Controls.PickWorkItemsControl to select the work items I need. After that the revsionsCollectoin is compleet. Maybe this helps:

// select the workitems using the picker
ArrayList workItems = _workItemPicker.Control.SelectedWorkItems();

// after that use a foreach and output all history included in each revision
private void PrintHistory(WorkItem workitem)
{

        RevisionCollection revisions = workitem.Revisions;

        foreach (Revision revision in revisions)
        {
            String history = (String) revision.Fields["History"].Value;
            Console.WriteLine("**** Revision {0}", revision.Fields["Title"], revision.Fields["Changed Date"]);

            foreach (Field field in revision.Fields)
            {
                Console.WriteLine("* field {0}:{1} ", field.Name, field.Value);
            }

            Console.WriteLine("****");
            Console.WriteLine();
        }

} 
A: 

Where are you getting the workitem? I know when I was getting version history of files with sourceControl.QueryHistory I had to set one of my parameters (bool include Changes) to true in order to get the changes in the changeset.

Ryan