I have been asked to write a few times custom controls that requires me to get the users from the Team Project.
The method that does that is very simple, the example in this post takes the members from the project by the “project name” that was passed to it, and adds them to a combobox named cmbUsers.
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Proxy;
using Microsoft.TeamFoundation.Server;
public void GetUsers(TeamFoundationServer server, string project)
{
cmbUsers.Items.Clear();
IGroupSecurityService securityService =
(IGroupSecurityService)server.GetService
(typeof(IGroupSecurityService));
Identity[] projectGroups =
securityService.ListApplicationGroups
(store.Projects[project].Uri.AbsoluteUri);
foreach (Identity projectGroup in projectGroups)
{
Identity[] groupMembers =
securityService.ReadIdentities
(SearchFactor.Sid, new string[]
{ projectGroup.Sid },
QueryMembership.Expanded);
foreach (Identity member in groupMembers)
{
if (member.Members != null)
{
foreach (string memberSid in member.Members)
{
Identity memberInfo=
securityService.ReadIdentity
(SearchFactor.Sid, memberSid,
QueryMembership.None);
cmbUsers.Items.Add(memberInfo.DisplayName);
}
}
}
}
}
Have Fun!!!