AustinT
AustinT

Reputation: 2026

TFS SDK 2013 Get Team names in a given team project

Hello can someone please help me with getting all the teams in a given team project.

Current code gets all Team Projects (from http://msdn.microsoft.com/en-us/library/bb286958.aspx)

    public void getTeamProjects()
    {
        TfsConfigurationServer configServer = TfsConfigurationServerFactory.GetConfigurationServer(_uri);
        ReadOnlyCollection<CatalogNode> collectionNodes = configServer.CatalogNode.QueryChildren(
            new[] { CatalogResourceTypes.ProjectCollection },
            false, CatalogQueryOptions.None);

        foreach (CatalogNode collectionNode in collectionNodes)
        {
            Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
            TfsTeamProjectCollection teamProjectCollection = configServer.GetTeamProjectCollection(collectionId);
            Console.WriteLine("Collection: " + teamProjectCollection.Name);

           ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
           new[] { CatalogResourceTypes.TeamProject },
           false, CatalogQueryOptions.None);

           foreach (CatalogNode projectNode in projectNodes)
           {
               Console.WriteLine("Team Project: " + projectNode.Resource.DisplayName);
               // How do I access the Team names of each projectNode.
           }

        }

        Console.WriteLine("Finished");
        Console.ReadKey();
    } 

Currently on the console it is printing out all of the Team Projects correctly. I want the ability to access the team names in each team project.

Upvotes: 1

Views: 2832

Answers (1)

jessehouwing
jessehouwing

Reputation: 114461

Check the source code for the TFS Team Tools from the ALM Rangers over on codeplex. The ListTeams method does exactly what you're after.

this.teamService = this.teamProjectCollection.GetService<TfsTeamService>();

public List<string> ListTeams()
{
    var teams = this.teamService.QueryTeams(this.projectInfo.Uri);
    return (from t in teams select t.Name).ToList();
}

Upvotes: 2

Related Questions