How to access TFS work items using TFS API

We can access Team foundation servers using TFS object model.
Following is the code to connect to TFS and read work items for particular TFS projects.

using System.Net;
protected void ConnectToTFS()
NetworkCredential account = new NetworkCredential(USER_NAME, PASSWORD, DOMAIN);
TeamFoundationServer server = new TeamFoundationServer(TFSSERVERName);
Project project = null;

WorkItemStore store = new WorkItemStore(server);
project = store.Projects[PROJECTNAME];
if (project == null)
throw new Exception("Project could not found");
string wiql = "SELECT [System.Id], [System.Title], [System.Description] " +
"FROM WorkItems " +
"WHERE [System.TeamProject] = '" + PROJECT + "' " +;

WorkItemCollection collection = store.Query(wiql);

//Collection Object will have all the workitems from the project specified.
catch (Exception ex)
throw ex;

We have used WIQL - Work Item Query Language. Its same as SQL.
To read more about WIQL browse this


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: