Connect to TFS 2010 using API

Using TFS API, you can access/manage  any part in team foundation server. The most common use of API’s is to create custom service to help better on your work, such as ( build automation, workitem management , migration from other tools, create custom tool, reports ,collect measurements….ect)

In this article i will start by simple task which is, connecting to single team project collection using c#.

1. Create new C# project

2. Add team foundation server Dll references as

3. Add button on the form and rename it to connect,

4. Double click on the button to write this code,

try

{

TeamFoundationServer server;

System.Net.NetworkCredential _credential = (System.Net.NetworkCredential)System.Net.CredentialCache.DefaultCredentials;

server = new TeamFoundationServer(”http://TFSSERVER:8080/tfs/COLLECTIONNAME”, _credential);

server.Authenticate();

if (false == server.HasAuthenticated)

{

MessageBox.Show(”Could not authenticate while connecting to tfs”);

}

MessageBox.Show(”Connect To TFS”);

}

catch (Exception _ex)

{

System.Windows.Forms.MessageBox.Show(_ex.Message);

throw;

}

 

Enhanced by Zemanta

2 thoughts on “Connect to TFS 2010 using API

  1. Hey, Thanks for this post Its really easy to understand. I would like to give a try for How to connect with specific credentials using C# code and fetch the projects from TFS

Leave a Reply

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