Can we download the files attached to workitems in RTC?
I need to export files attached to multiple work items in one folder. is this possible using any plug in. |
2 answers
Ralph Schoon (63.5k●3●36●46)
| answered Oct 09 '17, 9:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER You can create yourself a tool: https://rsjazz.wordpress.com/2012/09/21/downloading-attachments-from-work-items/
|
I have done that in a plugin (follow-up action), using server-side Java API.
This works for only one work item, but you can use thes snippets as a starting point, by adapting them to plain Java API.
public IAttachment getAttachment (IWorkItem workItem)
throws TeamRepositoryException {
IAttachment attachment = null;
IWorkItemReferences workItemReferences = saveParameter.getNewReferences();
List<IReference> attachmentReferencesList = workItemReferences.getReferences(WorkItemEndPoints.ATTACHMENT);
for (IReference attachmentReference : attachmentReferencesList) {
if (attachmentReference.isItemReference()) {
IItemHandle referencedItem = ((IItemReference) attachmentReference).getReferencedItem();
String itemKind = referencedItem.getItemType().getName();
if (referencedItem instanceof IAttachmentHandle) {
attachment = (IAttachment) repositoryItemService.fetchItem(referencedItem, IRepositoryItemService.COMPLETE);
break;
}
}
}
return attachment;
}
public boolean saveAttachment(IAttachment attachment)
throws TeamRepositoryException {
boolean saved = false;
try {
String attachmentName = attachment.getName();
String attachmentPath = attachmentsFolder + "\" + attachmentName;
File save = new File(attachmentPath);
OutputStream out = new FileOutputStream(save);
try {
contentService.retrieveContent(attachment.getContent(), out);
} finally {
out.close();
}
saved = true;
} catch (FileNotFoundException e) {
saved = false;
} catch (IOException e) {
saved = false;
}
return saved;
}
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.