I experienced exactly the same behavior, and unfortunately @JWC's answer did not help. A solution that works for me can be found at this link .
So, this is a brief summary in case of loss of the original answer.
The key point is to use the WorkItemServer class. He lives in the Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll assembly.
First of all, you create an instance of WorkItemStore :
var store = collection.GetService<WorkItemStore>();
Then create the necessary iteration paths:
var commonservice = collection.GetService<ICommonStructureService>(); var iterationRoot = commonservice.GetNodeFromPath("\\MyTeamProject\\Iteration"); var newIterationPath = commonservice.CreateNode("my sprint", iterationRoot.Uri);
Then update the cache in TFS (I suspect this is similar to pressing F5 in the web interface):
var wiServer = collection.GetService<WorkItemServer>(); wiServer.SyncExternalStructures(WorkItemServer.NewRequestId(), commonservice.GetProjectFromName("MyTeamProject").Uri); store.RefreshCache();
And finally, assign the newly created work item the newly created iteration:
var wi = new WorkItem(store.Projects["MyTeamProject"].WorkItemTypes["Product Backlog Item"]); wi.Title = "Hello from API"; wi.Description = "This work item was created from API"; wi.Fields["Assigned To"].Value = "Yan Sklyarenko"; wi.IterationPath = FormatPath(commonservice.GetNode(newIterationPath).Path, "Iteration", "MyTeamProject"); wi.Save();
What is it! The FormatPath method takes the iteration path to the form required by the IterationPath work item field, from \MyTeamProject\Iteration\my sprint to MyTeamProject\my sprint .
Hope this can save some time.
NOTE. I am running this for TFS 2013.