Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

tfs

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;

}
like image 361
Amr Ramadan Avatar asked Aug 05 '10 09:08

Amr Ramadan


People also ask

How do I get a project from TFS server?

In the Add/Remove Team Foundation Server dialog box, click Close. In the Connect to Team Project dialog box, select the TFS instance you want to connect to, select the team project collection you want to add to, and then click Connect.

How do I connect to TFS?

Select the Manage Connections button in Team Explorer to open the Connect page. Choose Connect to Team Project to select a different organization, TFS, or project to connect to. Select the projects to work on. If it's your first time connecting, add TFS to the list of recognized servers.

How can I add Source Control in Visual Studio 2019?

From the main menu, Tools -> Options and then navigate to. Under the Plug-in Selection, you will find it is already set to “None. From the plug-in selection drop-down, you can choose either Git or Visual Studio Team Foundation Server. Visual Studio will enable the plugin for the specific source control accordingly.

How do I get the latest TFS code?

Right-Click In the File List, right-click the file you want to get and select Source Control > Get Latest Version.


2 Answers

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.

like image 105
Jeff Bramwell Avatar answered Sep 29 '22 05:09

Jeff Bramwell


try this

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

good luck

like image 44
Shahyad Sharghi Avatar answered Sep 27 '22 05:09

Shahyad Sharghi