Paul Hacker's Blog

Musings from a "Hacker"
posts - 21, comments - 65, trackbacks - 22

My Links

News



Archives

Wednesday, August 02, 2006

Programmatically show the Connection Dialog for Team Foundation

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.

  1. AllowMultiSelect - Lets the user select multiple projects
  2. 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.

posted @ Wednesday, August 02, 2006 9:29 PM | Feedback (3) |

Powered by: