Posts mit dem Label TFS 2012 API werden angezeigt. Alle Posts anzeigen
Posts mit dem Label TFS 2012 API werden angezeigt. Alle Posts anzeigen

Dienstag, 19. Februar 2013

TFS 2012 API - Get all work items assigned to a user

Just playing around with TFS API. I always have to remeber how to start, so I document my findings here, as a reference for me - and maybe it might help someone else...

So if you want to query all WorkItems assigned the current user you first have to reference

  • Microsoft.TeamFoundation.Client
  • Microsoft.TeamFoundation.Common
  • Microsoft.TeamFoundation.WorkItemTracking.Client
Then use the following code:

var collection = new TfsTeamProjectCollection(new Uri("http://nb-tri:8080/tfs/defaultcollection"));
collection.EnsureAuthenticated();

var query =
    "SELECT * " +
    "FROM WorkItems " +
    "WHERE [System.TeamProject] = @project and " +
    "      [System.WorkItemType] <> '' and " +
    "      [System.State] <> '' and " +
    "      [System.AssignedTo] = @user " +
    "ORDER BY [System.Id] ";

var wiStore = collection.GetService<WorkItemStore>();
var parameter = new Dictionary<string, string>
    {
        {"project", "ScrumTest"},
        {"user", collection.AuthorizedIdentity.DisplayName}
    };
var result = wiStore.Query(query, parameter);


That's it... easy, isn't it?