Reputation: 23
I am getting WorkItems from TFS using this code:
private static List<WorkItem> GetTfsWorkItems(string projectName)
{
Uri URI = new Uri("...", UriKind.Absolute);
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(URI);
WorkItemStore store = new WorkItemStore(tpc);
string query = $@"SELECT *
FROM WorkItems
WHERE [System.TeamProject] = '{projectName}'";
return store.Query(query).Cast<WorkItem>().ToList();
}
WorkItem have fields "CreatedBy" and "ChangedBy" both of which are strings with user's DisplayName. I am looking for way to get user's AccountName (or Sid) instead of it. Thanks in advance!
Upvotes: 2
Views: 363
Reputation: 51073
It's not able straightforward to get the AccountName. Fields with username values like the CreatedBy/ChangedBy field are stored in the TFS database as a reference to an identity, not simply as the display name.
However querying the list of accounts by display name is not supported. As a workaround you have to dig into the account list and match the display name to an identity. That identity has your AccountName.
With help of TeamFoundationIdentity
, you could get what you need. Take a look at below tutorials with more details:
Upvotes: 1