简体   繁体   中英

How to connect with TFS and get list of projects for a specific user

public List<string> ListAllProjects(){    
TeamFoundationServer teamFoundationServer =
     TeamFoundationServerFactory.GetServer(@"http:\\ld-tfs08sp1:8080\\");    

teamFoundationServer.Authenticate();    
WorkItemStore workItemStore = new WorkItemStore(@"http:\\ld-tfs08sp1:8080\\");    

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

foreach (Project pr in workItemStore.Projects)    
{
        list.Add(pr.Name);    
}    

if (list.Count == 0)        
      list.Add("Not Found");    

return list;

}

Here is an example that will retrieve a list of Team Projects for a given Team Project Collection (TPC) in TFS 2010:

static void Main(string[] args)
{
    var results = GetTfsProjects(new Uri("http://mytfsserver:8080/tfs/DefaultCollection"));
}

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;
}

Hope this helps.

try this

var TeamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(teamProjectCollectionUrl);
var commonStruct = TeamProjectCollection.GetService<ICommonStructureService>();
var teamProjectInfos = commonStruct.ListAllProjects();

good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM