First this was a very easy task but it was my first task of TFS SDK and WIQL (Work Item Query Language), in this postI will Create and retrieve work items using TFS API and WIQL
To retrieve work items like task we will use the following code snippet
public void RetrieveWorkItems()
{
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new
Uri("http://TFS2011:8080/TFS/DefaultCollection"));
var workItemStore = tfs.GetService<WorkItemStore>();
var wiqlQuery = String.Format( @"Select [State], [Title] From
WorkItems Where [Work Item Type] = 'Task' Order By [State] Asc,
[Changed Date] Desc"); ;
WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);
foreach (WorkItem workItem in witCollection)
{
Console.WriteLine("ID: {0}", workItem.Id);
Console.WriteLine("Title: {0}", workItem.Title);
}
}
To create work items like task we will use the following code snippet
public void CrateTask()
{
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new
Uri("http://TFS2011:8080/TFS/DefaultCollection"));
var workItemStore = tfs.GetService<WorkItemStore>();
Project proj = workItemStore.Projects["SimpleTry"];
WorkItemType type = proj.WorkItemTypes["Task"];
WorkItem workItem = new WorkItem(type);
workItem.Title = "Task entered using API";
workItem["Activity"] = "Configuration";
workItem.Save();
}
Fore more information on how to use TFS SDK click here
For more information on how to use WIQL (Work Item Query Language) click here
Fore more information click here