TFS API Part 14: Export Work Item Definition

11/02/2009

no comments

TFS API Part 14: Export Work Item Definition

In this post I’ll show how to Export work item definition using TFS API.

This action can be used for Backups script or even for third party for Work Item definition editor.

image

Download Demo

First add reference for Microsoft.TeamFoundation, Microsoft.TeamFoundation.Client, Microsoft.TeamFoundation.Common.dll,Microsoft.TeamFoundation.WorkItemTracking.Client.dll
located in – C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\

Add using for:

using Microsoft.TeamFoundation.Proxy;

using Microsoft.TeamFoundation.Client;

using Microsoft.TeamFoundation.WorkItemTracking.Client;

 

Connect to TFS:

 

DomainProjectPicker dp = new DomainProjectPicker(DomainProjectPickerMode.None);

 

dp.ShowDialog();

 

if (dp.SelectedServer != null)

{

    tfs = new TeamFoundationServer(dp.SelectedServer.Name, new UICredentialsProvider());

    tfs.EnsureAuthenticated();

    store = (WorkItemStore)tfs.GetService(typeof (WorkItemStore));

    GetProject();

}

Get TFS Project List:

private void GetProject()

{

    foreach (Project p in store.Projects)

    {

        cob_projects.Items.Add(new ProjectType(p));

    }

}

public class ProjectType

{

    public string Name { get; set; }

    public WorkItemTypeCollection WitTypeCollection { get; set; }

 

    public ProjectType(Project proj)

    {

        this.Name = proj.Name;

        this.WitTypeCollection = proj.WorkItemTypes;

    }

    public override string ToString()

    {

        return this.Name;

    }

}

 

Calling Export Method

private void Export(string m_projectname, string m_type)

{

    try

    {

        XmlDocument xml_e = store.Projects[m_projectname].WorkItemTypes[m_type].Export(global.IsChecked.Value);

        txt_definition.Text = xml_e.InnerXml;

    }

    catch (WorkItemTypeDeniedOrNotExistException ex)

    {

        MessageBox.Show(ex.Message);

    }

}

Download Demo

Add comment
facebook linkedin twitter email

Leave a Reply