Dor Zohar
Dor Zohar

Reputation: 199

getting user list from the team project your in at TFS 2012 using C#

My goal is to get the whole information of the users that are in the teamproject my user is in. Then I want to to get the email addresses of the users and send them the id of the task they have been assigned. (It's an exercise)

I succeed in connecting to the server with the following code:

TfsTeamProjectCollection tfs = new TfsProjectCollection(new Uri(tfsUri));
ITeamProjectCollectionService tpcService = tfs.GetService<ITeamProjectCollectionService>();

but I don't know how to continue from this point.

I searched for a solution but didn't find any good material.

Upvotes: 1

Views: 5504

Answers (2)

Richard Arnold
Richard Arnold

Reputation: 361

You can retrieve (all) users from the TFS Api by using the IIDentityManagementService.

IIdentityManagementService identityManagementService = tpcService.GetService<IIdentityManagementService>();
TeamFoundationIdentity[][] identities = 
    IdentityManagementService.ReadIdentities(
        IdentitySearchFactor.AccountName,
        new[] { "Project Collection Valid Users" },
        MembershipQuery.Expanded,
        ReadIdentityOptions.ExtendedProperties);
    

And then print out all E-Mails

foreach (var user in identities) {
    Console.WriteLine(user.GetAttribute("Mail", null));
}

Upvotes: 3

Tamir Daniely
Tamir Daniely

Reputation: 1710

_identityManagementService = _collection.GetService<IIdentityManagementService2>();
var validUsers = _identityManagementService.ReadIdentities(IdentitySearchFactor.AccountName, new[] { "Project Collection Valid Users" }, MembershipQuery.Expanded, ReadIdentityOptions.None)[0][0].Members;
var users = _identityManagementService.ReadIdentities(validUsers, MembershipQuery.None, ReadIdentityOptions.None).Where(x => !x.IsContainer).ToArray();

users will hold simple objects, inspect the objects in debug to see available properties. In the second ReadIdentities you can play with the MembershipQuery and ReadIdentityOptions parameters to get more information about the users.

Upvotes: 2

Related Questions