In order to begin, first you need to create a C# class in your project and add the following code:
If you want to connect to the TFS Team Project with hard coded values you can use the following code:
|Uri tfsUri = new Uri(“http:mytfsuri.comteamCollection“);|
|string teamProjectName = “TestProject“;|
|TfsTeamProjectCollection myTfsTeamProjectCollection = new TfsTeamProjectCollection(tfsUri);|
First you initialize new URI object with your team collection URL which is equal to your TFS URL plus your team collection name. After that, you should create a collection object and initialize it with the URI. You use “GetService” method to initialize the TFS service. Then you can get the team project from it.
Collect TFS Settings with TeamProjectPicker Dialog
In order to capture the needed connection information, you can add TeamProjectPicker object to your windows app. You can use its method “ShowDialog” in order to collect the information.
|var userSelected = projectPicker.ShowDialog();|
|if (userSelected == DialogResult.Cancel)|
|if (projectPicker.SelectedTeamProjectCollection != null)|
|Uri tfsUri = = projectPicker.SelectedTeamProjectCollection.Uri;|
|string teamProjectName = projectPicker.SelectedProjects.Name;|
|TfsTeamProjectCollection myTfsTeamProjectCollection = projectPicker.SelectedTeamProjectCollection;|