Seiyria
Seiyria

Reputation: 2132

Getting "subprojects" (teams?) in TFS 2012

Similar to this, I want to get all projects listed under a user. I'm currently working with the code from the link before:

private static List<string> GetTfsProjects(Uri tpcAddress)
{
    var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcAddress);

    tpc.Authenticate();

    var workItemStore = new WorkItemStore(tpc);
    var projectList = (from Project pr in workItemStore.Projects select pr.Name).ToList();

    return projectList;
}

..but it's only returning "LSWebsite" (my URI is h ttp://server:port/defaultcollection). How do I get LSWebsite and its children? Image below shows the hierarchy I'm currently working with.

Sample hierarchy image

Upvotes: 2

Views: 532

Answers (1)

DaveShaw
DaveShaw

Reputation: 52808

Those look like teams.

Try this snippet:

var teamService = tpc.GetService<TfsTeamService>();

var teams =
        projectList
        .SelectMany(
            projectId =>
                teamService
                .QueryTeams(projectId)
                .Select(t =>  String.Format("{0}\\{1}", projectId, t.Name)))
        .ToArray();

projectList.AddRange(teams);

Taken from Shai's blog here.

Upvotes: 2

Related Questions