TFS Team Project Names through C#

As in previous post, i have mention to Connect the TFS through Client Object Model,

Now in this post i elaborate to find the name of Team Project Name programically through C#

Just simply copy paste the given code in console application it will works

using System;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Net;

namespace TfsApplication
class Program
static void Main(String[] args)
List<SelectListItem> listTeam = new List<SelectListItem>();
//string lblMessage = “”;//
DataTable tableTeam = new DataTable();

List<string> teamPro = ListOFTeamProjectCollections();
foreach (string TID in teamPro)

public static List<string> ListOFTeamProjectCollections()




List<string> teamPro = new List<string>();

var collectionUri = new Uri(“http://SERVERIP:8080/tfs/PROJECTCOLLECTION&#8221;);

TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(collectionUri, new NetworkCredential(“USERNAME”, “PASSWORD”, “DOMAIN”));


ICredentialsProvider provider = new UICredentialsProvider();

TfsConfigurationServer configurationServer = tfs.ConfigurationServer;

CatalogNode catalogNode = configurationServer.CatalogNode;

ReadOnlyCollection<CatalogNode> tpcNodes = catalogNode.QueryChildren(

new Guid[] { CatalogResourceTypes.ProjectCollection },

false, CatalogQueryOptions.None);

foreach (CatalogNode tpcNode in tpcNodes)


Guid tpcId = new Guid(tpcNode.Resource.Properties[“InstanceId”]);

TfsTeamProjectCollection tpc = configurationServer.GetTeamProjectCollection(tpcId);


ReadOnlyCollection<CatalogNode> tpNodes = tpcNode.QueryChildren(

new Guid[] { CatalogResourceTypes.TeamProject },

false, CatalogQueryOptions.None);

foreach (CatalogNode tpNode in tpNodes)





return teamPro;


catch (Exception e)






Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s