Get the list of projects and teams from TFS
The following code will give a list of projects from TFS:
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
TfsContext.TeamFoundationServerUrl = ConfigurationManager.AppSettings.Get("TeamProjectCollectionUrl");
var collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TfsContext.TeamFoundationServerUrl));
private static ICommonStructureService _commonStructureService;
_commonStructureService = collection.GetService<ICommonStructureService>();
var projects = _commonStructureService.ListAllProjects();
The following code will give a list of teams from TFS:
private readonly ICommonStructureService4 _commonStructureService;
var collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TfsContext.TeamFoundationServerUrl));
_commonStructureService = collection.GetService<ICommonStructureService4>();
string teamProjectUri = _commonStructureService.GetProjectFromName("projectname").Uri;
var teams = _teamService.QueryTeams(teamProjectUri);