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()
{
try
{
NetworkCredential account = new NetworkCredential(USER_NAME, PASSWORD, DOMAIN);
TeamFoundationServer server = new TeamFoundationServer(TFSSERVERName);
Project project = null;
server.Authenticate();
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;
}
finally
{
}
}
We have used WIQL - Work Item Query Language. Its same as SQL.
To read more about WIQL browse this
msdn.microsoft.com/en-us/library/bb130319(VS.80).aspx