Saturday, September 19, 2009

Import TFS Workitems through C# code

This is how you can import the TFS workitems through C# code
            NetworkCredential objCre = new NetworkCredential(txtUserName.Text, txtPassword.Text, "TFS");
            WebProxy objProxy = new WebProxy();
            objProxy.Credentials = CredentialCache.DefaultCredentials;
            TeamFoundationServer tfs1 = new TeamFoundationServer(txtTFSServer.Text, objCre);
            tfs1.EnsureAuthenticated();

            WorkItemStore store = (WorkItemStore)tfs1.GetService(typeof(WorkItemStore));
          
            WorkItemCollection objColl = store.Query("SELECT   [System.Id], [System.WorkItemType], [Microsoft.VSTS.Common.Rank], [System.State], [System.AssignedTo], [System.Title]  FROM     WorkItems  WHERE    [System.TeamProject] = 'Sample'   AND      [System.WorkItemType] ='Bug' AND [System.Title] CONTAINS '-ST-' ");



Before running this code ensure that you download and install the TFS SDK from microsoft site.
The following are the references you will have to add to the project
Microsoft.TeamFoundation.Client
Microsoft.TeamFoundation.WorkItemTracking.Client

No comments:

Post a Comment