how to connect to TFS by authentication (Team foundation server) in your asp.net web form?

1.8k views Asked by At

I'm trying to create a page where I will be getting all the Workitem in the tfs. But I don't know how to Connect to TFS. what reference I need to add currently my code is ( which I get from internet ).

NetworkCredential credential = new NetworkCredential("username", "password");  
BasicAuthCredential basicCred = new BasicAuthCredential(credential);  

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(  
new Uri("https://project.visualstudio.com/DefaultCollection"),  
basicCred);  

tpc.Authenticate(); 

code with error enter image description here

1

There are 1 answers

5
Pedram On

First of all, add this library using nuget:

Microsoft.TeamFoundationServer.ExtendedClient

Also you need this namespace, so you should add it to the page:

Microsoft.TeamFoundation.Client

Then you can connect to TFS with following code:

var collectionUri = new Uri("https://project.visualstudio.com/DefaultCollection");

var credential = new NetworkCredential("username", "password");
var teamProjectCollection = new TfsTeamProjectCollection(collectionUri, credential);
teamProjectCollection.EnsureAuthenticated();