It's all about the answers!

Ask a question

Can we download the files attached to workitems in RTC?


Neha Nayak (1547) | asked Oct 09 '17, 8:53 a.m.

I need to export files attached to multiple work items in one folder. is this possible using any plug in.

2 answers



permanent link
Ralph Schoon (63.3k33646) | answered Oct 09 '17, 9:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

permanent link
Luca Martinucci (1.0k396112) | answered Oct 10 '17, 2:44 a.m.

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


Register or to post 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.