Search Wiki:

Connect to a Project Collection


This sample illustrates how to connect to a team project collection by Uri. Passing in a UICredentialsProvider instance will cause the call to EnsureAuthenticate to prompt the user for credentials if their default credentials aren't sufficient and if they don't have applicable cached credentials.

Using
System.Net;
Microsoft.TeamFoundation;
Microsoft.TeamFoundation.Client;

// Connect to a project collection by Uri
try
{
    var projectCollectionUri = new Uri("http://tfs2010:8080/tfs/MyCollection");
    var projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(projectCollectionUri, new UICredentialsProvider())
    projectCollection.EnsureAuthenticated();
}
catch (TeamFoundationServerUnauthorizedException ex)
{
    // handle access denied
}
catch (TeamFoundationServiceUnavailableException ex)
{
    // handle service unavailable
}
catch (WebException ex)
{
    // handle other web exception
}
Last edited Feb 24 2010 at 8:30 PM  by JimLambTFS, version 2
Updating...
Page view tracker