The Work Item Object Model sample includes seven different projects, each of which creates one console application. Each console application shows the individual parts of the Work Item Object Model.
Attachments
Linking
Query
StoredQuery
WorkItemEdit
WorkItemNew
WorkItemType
You will find two solution files. One is C# and the other is Visual Basic. Each language offers the same functionality.
To build all the projects
In the Sample Browser, right click C# Example.UsingTheWorkItemObjectModel and choose Open in VS.
Press F5 to build the sample.
To see each console application
Requirements
Team Foundation Server installation and the name of the server.
A computer that has Visual Studio installed.
A computer that has Team Explorer installed.
Demonstrates
Attachments Project
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Creates a new WorkItem in the first project on the server.
Adds OnFieldChanged to handle the workItem.FieldChanged events.
Adds two attachments, Hello World.txt and Sunset.jpg.
Saves the WorkItem.
Removes the second attachment.
Saves the WorkItem again.
|
OnFieldChanged() |
|
OutputAttachments() |
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
Linking
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Creates a new WorkItem in the first project on the server.
Adds a HyperLink to https://www.microsoft.com.
Adds a second WorkItem and saves it.
Creates a RelatedLink to the second WorkItem.
Displays the list of RegisteredLinkTypes.
Creates and adds an ExternalLink of the first RegisteredLinkType.
Saves the WorkItem
Removes the ExternalLink.
Saves the WorkItem again.
|
OutputLinks() |
Displays on the console the details of the links in a LinkCollection.
This method is not accessed, but it is available if you want to customize or alter this program.
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
Query Project
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Creates a new WorkItem in the first project on the server.
Declares the WIQL query string.
Runs the query.
Displays the query results on the console.
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
StoredQuery Project
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Creates a new WorkItem in the first project on the server.
Lists all the stored queries in the first project.
Asks the user which query to run.
Displays the field names, and the fields returned by the query.
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
WorkItemEdit Project
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Creates a new WorkItem in the first project on the server, and then saves the WorkItem.
Edits the WorkItem by changing the workItem.Title.
Checks to see whether all fields are valid.
If all fields are not valid, displays the invalid fields and then exits.
Saves the WorkItem again.
Displays all revisions of the WorkItem's history.
Displays specific WorkItem fields and includes ChangedDate, History, and the changed fields that are display fields.
|
IsDisplayField() |
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
WorkItemNew Project
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Gets the collection of WorkItemTypes from the first project.
Creates a new WorkItem of type "Bug" in the first project on the server.
Checks to see whether all fields are valid.
If all fields are not valid, displays the invalid fields and then exits.
Saves the WorkItem.
Transitions the WorkItem to its next state, and then saves the WorkItem again.
Displays all revisions of the WorkItem's history.
Displays specific WorkItem fields and includes ChangedDate, History, and the changed fields that are display fields.
|
IsDisplayField() |
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
WorkItemType Project
Main() |
Connects to the Team Foundation Server and the WorkItemStore.
Gets the collection of WorkItemTypes from all projects on the server.
Displays all projects, and all WorkItemTypes within each project.
|
GetServer() |
Returns the Team Foundation Server name from the environment variable "TEAM_FOUNDATION_SERVER_NAME."
If TEAM_FOUNDATION_SERVER_NAME is not defined, it asks for the server name from the console.
|
See Also
Reference
Work Item Revision History
Other Resources
Samples - Work Item Tracking
Work Item Tracking Extensibility