Connect TFS Azure using API

Many user ask’s how i connect to TFS service using new API’s, here is a sample of TFS connection and getting workitem using TFS API version

  • Open VS 2011 and create new C# project.
  • From references right click and choose add reference (Microsoft.TeamFoundation.Client.Microsoft.TeamFoundation.WorkItemTracking.Client)
  • Add this namespaces in top of the class
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
  •  Add below code to connect to TFS collection and show the ‘created by’ field for workitem number 4.
        TfsTeamProjectCollection server;
        WorkItemStore store;

        private void TFSconnect()
                TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.MultiProject, false);
                if (tpp.SelectedTeamProjectCollection != null)
                    server = tpp.SelectedTeamProjectCollection;
                    store = server.GetService(typeof(WorkItemStore)) as WorkItemStore;
                    WorkItem _WI = store.GetWorkItem(4);

            catch (Exception _ex)

If you want to connect without using ‘TeamProjectPicker’ use this code to get TFS collection

TfsTeamProjectCollection server = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(""));

Enjoy 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *