Saving the attachments to disk programmatically
Hi All,
Am using RTC 2002; Have a requirement of saving attachments on a workitem to disk programmatically; I did refer couple of postings in this forum and could not get any pointers from them.
Am getting a run time cast exception on running the code I have written. The exception looks something like below:
Exception in thread "main" java.lang.ClassCastException: com.ibm.team.workitem.common.internal.model.impl.AttachmentHandleImpl incompatible with com.ibm.team.workitem.common.model.IAttachment
at com.ibm.team.workitem.ide.ui.example.SaveAttachments.run(SaveAttachments.java:178)
at com.ibm.team.workitem.ide.ui.example.SaveAttachments.main(SaveAttachments.java:102)
snippet of the code I have written is pated below:
Any pointers/ guidance would be of great help. Many thanks in advance.
Regards,
Mohan.
Am using RTC 2002; Have a requirement of saving attachments on a workitem to disk programmatically; I did refer couple of postings in this forum and could not get any pointers from them.
Am getting a run time cast exception on running the code I have written. The exception looks something like below:
Exception in thread "main" java.lang.ClassCastException: com.ibm.team.workitem.common.internal.model.impl.AttachmentHandleImpl incompatible with com.ibm.team.workitem.common.model.IAttachment
at com.ibm.team.workitem.ide.ui.example.SaveAttachments.run(SaveAttachments.java:178)
at com.ibm.team.workitem.ide.ui.example.SaveAttachments.main(SaveAttachments.java:102)
snippet of the code I have written is pated below:
IWorkItemReferences fsrcReferences = srcWorkingCopy.getReferences();
List<IReference> srcAttachments = fsrcReferences.getReferences(WorkItemEndPoints.ATTACHMENT);
for (int i=0; i < srcAttachments.size(); i++) {
IReference srcReference = srcAttachments.get(i);
IItemReference attachmentReference = (IItemReference) srcReference;
IAttachmentHandle attachmentHandle = (IAttachmentHandle) attachmentReference.resolve();
IAttachment srcAttachment = (IAttachment) attachmentHandle;
String srcAttachmentName = srcAttachment.getName();
FileOutputStream fos = null;
try {
fos = new FileOutputStream("C:\\temp\\" + srcAttachmentName);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
IContentManager cm= srcTeamRepository.contentManager();
cm.retrieveContent(srcAttachment.getContent(), fos, null);
}
Any pointers/ guidance would be of great help. Many thanks in advance.
Regards,
Mohan.