More About Creating Work Item Using TFS API
More About Creating Work Item Using TFS API
First create the connection to TFS and Work Item Store.
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(ServerName);
WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
WorkItemTypeCollection workItemTypes = store.Projects[TFSProject].WorkItemTypes;
Open The Work Item With PartialOpen()
Opens this WorkItem for editing without transferring all the data about the work item over the wire.
Copy Work Item
WorkItem NewWIT = workitem.Copy();
WorkItem NewWITTask = workitem.Copy(workItemTypes["Task"]);
Reset Work Item
Reverts all changes that were made to this WorkItem since the last revision.
Related Link - Create a Work Item Relation between Work Items
RelatedLink rl = new RelatedLink(324);
workItem.Links.Add(rl);
Hyper Link - Create a Hyper Link
Hyperlink hl = new Hyperlink("http://blogs.microsoft.co.il/blogs/shair");
hl.Comment = "Shai Raiten Blog";
External Link - Create link to "Test Result" , "Changeset", "Version Item"
RegisteredLinkTypeCollection linkTypes = store.RegisteredLinkTypes;
RegisteredLinkType changeset = linkTypes["Changeset"];
RegisteredLinkType versionitem = linkTypes["Versioned Item"];
RegisteredLinkType testresult = linkTypes["Test Result"];
ExternalLink el1 = new ExternalLink(changeset, "53421");
ExternalLink el2 = new ExternalLink(versionitem, "$/BuildProject/Main/WindowsFormsApplication1/Form1.cs");
ExternalLink el3 = new ExternalLink(testresult, "UnitTest1 from tfsBuild@TFSRTM08 2008-09-24");
workItem.Links.Add(el1);
workItem.Links.Add(el2);
workItem.Links.Add(el3);
Remove Link
LinkCollection WITLinks = workitem.Links;
WITLinks.Remove(el1);
WITLinks.Remove(hl);
To add Iteration Path & Area Path you need to write the full path using \
workitem.IterationPath = @"Main\Project\Product\Item";
workitem.AreaPath = @"Main\Project\Product\Item";
Using Query to find Work Items
string query = "SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = 'MyProject'";
WorkItemCollection witlist = store.Query(query);