It's all about the answers!

Ask a question

Add attachments to work item


Kinny Kun (5183) | asked Feb 20 '09, 8:16 p.m.
Hi,

I'm trying to add attachments to the existing work item. Here is my code:

IWorkItemWorkingCopyManager wcm = workItemClient.getWorkItemWorkingCopyManager();
ItemProfile<IWorkItem> profile = ItemProfile.computeProfile(workitem);
wcm.connect(workItemHandle, profile, monitor);
WorkItemWorkingCopy wc = wcm.getWorkingCopy(workItemHandle);
IWorkItemReferences refs = wc.getReferences();

** It failed when get references with exception
"Feature not contained in access profile WorkItem"

Am I doing it right?

Then I tried to get the references with the following code and it ran through ok:

IWorkItemHandle handle = (IWorkItemHandle)wc.getWorkItem().getItemHandle();
IWorkItemReferences refs = workItemClient.resolveWorkItemReferences(handle, monitor);

After I got the references, I do (file is File object):

IReference ref = IReferenceFactory.INSTANCE.createReferenceFromURI(file.toURI(), file.getAbsolutePath());
if (ref != null) {
refs.add(WorkItemEndPoints.ATTACHMENT, ref);
}
wcm.save(new WorkItemWorkingCopy[]{wc}, monitor);

After save, I try to get the list of references from the work item to see if the work item save correctly. But the list of references is empty.

Any idea? Anything wrong with my code?

Thanks alot for the help, really appreciated.

Thanks!!

Be the first one to answer this question!


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.