How to copy many work items between team projects?
If I have a team project with a bunch of work items, that is not solved in this team project, how can I easily copy/move these work item to another team project?
I know I can copy one work item within the GUI, or maybe use Excel to copy a couple of work items, but is there another way?
Answers
Ed, here is some example code
WorkItemStore store = new WorkItemStore("ATName"); string wiqlFormat = @"Select id, title from WorkItems where [Area Path] under '{0}'"; // Query to cover all source items to be copied string wiqlQuery = String.Format(wiqlFormat, "SourceProjectName1OrAreaPath"); WorkItemCollection list = store.Query(wiqlQuery); foreach (WorkItem wi in list){
WorkItem copied = wi.Copy(); // creates unsaved copycopied.AreaPath =
"ProjecName2"; // target area path here, or project name for root if (copied.IsValid){
copied.Save();
}
// if not valid, log item id to review later which rule is getting voilated.}
All Replies
Workitem Object model has a way to copy workitems. WorkItem has a copy method that returns a copied unsaved workitem. You can change the AreaPath to new project in the copied workitem and call save. You are right that in UI you can copy only one item at a time. If you need sample code to do it, feel free to reply to this post.
Yes I would appreciate some sample code.
Thanks.
Ed, here is some example code
WorkItemStore store = new WorkItemStore("ATName"); string wiqlFormat = @"Select id, title from WorkItems where [Area Path] under '{0}'"; // Query to cover all source items to be copied string wiqlQuery = String.Format(wiqlFormat, "SourceProjectName1OrAreaPath"); WorkItemCollection list = store.Query(wiqlQuery); foreach (WorkItem wi in list){
WorkItem copied = wi.Copy(); // creates unsaved copycopied.AreaPath =
"ProjecName2"; // target area path here, or project name for root if (copied.IsValid){
copied.Save();
}
// if not valid, log item id to review later which rule is getting voilated.}
Hi Ed,
I've been working on a tool to do this; I've posted an early release on gotdotnet. There are some interesting complications involved when moving work items, stuff like:
- You can't delete work items in TFS, so what do you with the source work item?
- What if the destination Team Project doesn't have a matching work item type?
- Some fields like attachments can't just be copied over, they need to be downloaded and then re-attached.
Anyways, I took a shot at solving some of those issues - if you get a chance to look at the tool I'd love to hear your feedback.
Thanks!
Eric.
Hi Eric. Can't get your download from gotdotnet any more. Is there a new location?
Thanks


