using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Proxy;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TFS_Test_1
{
    //http://msdn.microsoft.com/en-us/magazine/cc163443.aspx
    public partial class Form1 : Form
    {
        
        private TfsTeamProjectCollection    _collection;
        private ProjectInfo                 _project;
        private WorkItemStore               _witStore;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            RetrieveWorkItems();
        }

        private void RetrieveWorkItems()
        {
            PickProject();
            if (_project == null) return;

            _witStore = new WorkItemStore(_collection);

            //http://nigelonagile.com/2010/09/08/173/
            WorkItemCollection wits = _witStore.Query(string.Format("Select * from Workitems where [Team Project] = '{0}'", _project.Name));
            
        }

        //http://blogs.msdn.com/b/team_foundation/archive/2010/04/20/using-the-teamprojectpicker-api-in-tfs-2010.aspx
        private void PickProject()
        {
            _project = null;
            _collection = null;

            using (TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false))
            {
                DialogResult result = tpp.ShowDialog();
                if (result == DialogResult.OK)
                {
                    _project = tpp.SelectedProjects[0];
                    _collection = tpp.SelectedTeamProjectCollection;
                }
            }
        }
    }
}

Last edited Feb 3, 2011 at 7:40 PM by fixitchris, version 2