Share via


How to: Get WorkItems with a WIQL Query

The Work Item Query Language (WIQL) allows SQL-like queries to get WorkItems. The Query returns a WorkItemCollection of all WorkItems that match the query string.

Example

The following example assumes a WorkItemStore exists by the name of workItemStore.

// Sample query string.
string wiqlQuery = "Select ID, Title from Issue where (State = 'Active') order by Title";

// Execute the query.
WorkItemCollection witCollection = workItemStore.Query(wiqlQuery);

// Show the ID and Title of each WorkItem returned from the query.
foreach (WorkItem workItem in witCollection)
{
    Console.WriteLine("ID: {0}", workItem.Id);
    Console.WriteLine("Title: {0}", workItem.Title);
}

See Also

Tasks

How to: Get a WorkItem

How to: Get a Previous Revision of a WorkItem

Concepts

Ways to Get a WorkItem