Friday, August 19, 2011

How to get members list for a Team Project using TFS API?

Try the following code. Rember I have written it for TFS08, so there may be some functions don't work well for TFS2010.

----------------------------------------------------------------------------------------------------------
public void printMemberList(string teamProject)
        {
           
          
                          
            TeamFoundationServer tfsServer = new TeamFoundationServer("TFS_Server_name");
            IGroupSecurityService sec = (IGroupSecurityService)tfsServer.GetService(typeof(IGroupSecurityService));

            VersionControlServer versionControl = (VersionControlServer)tfsServer.GetService(typeof(VersionControlServer));

            TeamProject tp = versionControl.GetTeamProject(teamProject);

            Identity[] appGroups = sec.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri);

            foreach (Identity group in appGroups)
            {

                Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);

                foreach (Identity member in groupMembers)
                {

       

                    if (member.Members != null)
                    {
                        foreach (string memberSid in member.Members)
                        {
                     
                            Identity memberInfo = sec.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);

                           
                            Console.WriteLine(member.DisplayName + "----" + memberInfo.DisplayName.ToString());
                          
                           
                            
                        }

                    }

                }

            }

        }

No comments:

Post a Comment