I am always looking for new ways to work with and extend Team Foundation Server. I happen to be working on one such project and I had a need to access the Connection dialog box that is available in TFS. I made the assumption that I could show that dialog and utilize it rather than reinvent the wheel. It took me a bit, but I found out that you can use the DomainProjectPicker class to access the dialog.
The first thing I did was to set two private variables in my class
private TeamFoundationServer tfsServer;
private string tfsProjectName;
The following code returns me an instance of the picker. The constructor is overloaded so I can set the mode using the DomainProjectPickerMode enum. The enum gives me the five options, two of which are listed here.
- AllowMultiSelect - Lets the user select multiple projects
- AllowProjectSelect - - Lets the user select a project
I am using the AllowProjectSelect mode as I only want the user to be able to select one project from the list
DomainProjectPicker projectPicker = new DomainProjectPicker(DomainProjectPickerMode.AllowProjectSelect);
Now that I have an instance of the picker, I want to gleen some information from it that I will use in my project. I need to get the TFS server and the project name. First off I will show the dialog and if the user clicks OK I will gather up my info.
if (projectPicker .ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//get the selected server
tfsServer = projectPicker .SelectedServer;
//get the selected project name from the ProjectInfo array. I will use the 0 index since I am only allowing the user to
//select one project and use the Name property to get the actual project name.
Microsoft.TeamFoundation.Server.
ProjectInfo[] projectInfo = projectPicker .SelectedProjects;
tfsProjectName = projectInfo [0].Name;
//Now I need to authenticate so tha I can use the server object later on
tfsServer.EnsureAuthenticated();
}
As you can see it is rather easy to take advantage of the connection dialog in your own projects that need to access TFS. Hope you find this useful.