Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Creating a WorkItem

Creating a WorkItem 

WorkItems are the essence of the Work Item Tracking Object Model. However, WorkItems exist within a context inside the Team Foundation system.

Context of a Work Item

At the top is the Team Foundation Server. The server stores the WorkItemStore, which is the database of information for the Team's Projects. You can access the Team Foundation Server in this manner:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("YourTfsServerNameHere");

The Team Foundation Server stores one WorkItemStore. This is where you want to access the Projects, FieldDefinitions, and RelatedLinks. To access the WorkItemStore:

WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));

Through the WorkItemStore, you can access the collection of Projects:

foreach (Project project in store.Projects)
    Console.WriteLine("Project Name: " + project.Name);

Each Project contains a list of WorkItemTypes that describe the various categories of WorkItems for that Project. "Bug", "Task", or "Scenario" are some examples of WorkItemTypes.

This is how to list all WorkItemTypes within a specific Project:

foreach (WorkItemType wit in project.WorkItemTypes)
    Console.WriteLine("WorkItemType Name: " + wit.Name);
    Console.WriteLine("WorkItemType Description: " + wit.Description);

When you know the type of WorkItem you want to create, you are ready to create a WorkItem:

WorkItem workItem = new WorkItem(wit);


If you already know the name of the Team Foundation Server, the Project, and the WorkItemType (in this case, a bug), you can create a WorkItem in this manner:

TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("YourTfsServerNameHere");
WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
Project project = store.Projects["YourProjectNameHere"];
WorkItemType workItemType = project.WorkItemTypes["Bug"];
WorkItem workItem = new WorkItem(workItemType);

See Also

Community Additions

© 2015 Microsoft