Unable to get attachments with TFS SDK for JAVA
-
24. dubna 2012 5:29
Hello,
I am trying to use the TFS SDK for JAVA to read the workitems from TFS. I am able to get the workitems but unable to get the attachment associated with the work item.
The following code does not get the attachments (even though the work item contains attachments):
int workItemId = 328605;
WorkItem completeWorkitem = workItemClient.getWorkItemByID(workItemId);
AttachmentCollection attachments = completeWorkitem.getAttachments();
Iterator<Attachment> iterator = attachments.iterator();
while (iterator.hasNext()) {
Attachment attachment = iterator.next();
}I tried to iterate the fields which has attachement data:
<AttachmentMetadataContainer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<IsSAPCall>false</IsSAPCall>
<CopiedFromId>0</CopiedFromId>
<Metadata>
<AttachmentMetadataEntry>
<UploaderIdentifier>S-1-5-21-4269904857-2710872479-4003275499-5602</UploaderIdentifier>
<UploaderDisplayName>XXX</UploaderDisplayName>
<FileCreationDate>2012-03-21T17:44:20.9188784+01:00</FileCreationDate>
<FileName>yyy.png</FileName>
<Comments>
<AttachmentMetadataComment>
<CommentDate>2012-03-21T17:46:26.16341+01:00</CommentDate>
<CommentUser>XXX</CommentUser>
<Comment />
</AttachmentMetadataComment>
</Comments>
<AddedOn>2012-03-21T17:46:23.29341+01:00</AddedOn>
<FileSizeInBytes>34263</FileSizeInBytes>
<LocalFileName>D:\Work\MY-Files\Test100\ErrorInvalidCharacter.png</LocalFileName>
<WorkItemId>328605</WorkItemId>
</AttachmentMetadataEntry>
</Metadata>
<ChangedDate>2012-03-21T17:46:26.22341+01:00</ChangedDate>
</AttachmentMetadataContainer>
The download functionaloty requires FileID but it is not available in this attachment data. Please let me know how to download the attachments to local system.
Thanks,
Ram
Ram
- Změněný typ Ramakrishna_Rao 25. dubna 2012 8:28 Need answer
Všechny reakce
-
27. dubna 2012 20:41
You have have the Attachment object in your iterator. The attachment object has the Attachment.downloadTo(File target) method. This would download the attachment from the server and store it to a local file (target). Have you tried this?
Thanks,
Rick- Navržen jako odpověď Rick Potts MSFT 27. dubna 2012 20:41
- Zrušeno navržení jako odpověď Ramakrishna_Rao 30. dubna 2012 4:16
-
30. dubna 2012 4:16
Hello Rick,
Thanks for your response.
The attachments collection is empty and hence it does not enter inside the while loop. So I could not access the downloadTo method.
Is it possible to create the Attachment object dynamically from the xml data provided above, if so where to get the File ID information.
Thanks,
Ram
Ram
-
1. května 2012 21:05
I just experimented the following snippet to download an attachment from a work item with an attachment. It correctly downloaded the attachment.
for (Attachment attachment : workItem.getAttachments())
{
attachment.downloadTo(new File("<filepath>");
}
Can you verify you do indeed have an attachment on the work item? Also, what type of work item is it?Thanks,
Rick- Navržen jako odpověď Rick Potts MSFT 8. května 2012 21:17
-
2. května 2012 9:04
Hello Rick,
Yes, the work item has attachements (2 png files), and the WorkItem type is "Call". I can see the attachments in the Miscrosoft Visual Studio IDE (with TFS) and able to open them.
The following code does not enter into the for loop to get the attachments.
TFSTeamProjectCollection tpc = new TFSTeamProjectCollection(SnippetSettings.COLLECTION_URL, SnippetSettings.USERNAME, SnippetSettings.DOMAIN,
SnippetSettings.PASSWORD, SnippetSettings.HTTP_PROXY_URL, SnippetSettings.HTTP_PROXY_USERNAME, SnippetSettings.HTTP_PROXY_PASSWORD);Project project = tpc.getWorkItemClient().getProjects().get(SnippetSettings.PROJECT_NAME);
WorkItemClient workItemClient = project.getWorkItemClient();WorkItem completeWorkitem = workItemClient.getWorkItemByID(328605);
for (Attachment attachment : completeWorkitem.getAttachments()) {
attachment.downloadTo(new File("C:\\temp\\" + attachment.getFileName()));
}Is there any other setting in the WorkItemClient / Context to makesure attachements are downloaded.
I get the following error messages while executing the application but it continues get the work item:
ERROR [main] PlatformUtilsProxy - Proxy 'SecureStorage.defaultProxy' ran out of implementations to use
ERROR [main] PlatformUtilsProxy - Proxy 'NegotiateEngine.negotiateProxy' ran out of implementations to use
Thanks,
Ram
- Upravený Ramakrishna_Rao 2. května 2012 12:14
-
2. května 2012 14:47
I'm puzzled. Are you able to open this work item in Team Explorer Everywhere and see the attachments?
Thanks,
Rick -
10. května 2012 4:32
Hello Rick,
Sorry for the delay in response, I was deviated with different tasks.
I tried Team Explorer Everywhere in Eclipse. When I open the Work item with attachments, the Attachments tab is not created properly due "Unsupported custom control (AttachmentMgmtCtrl)".
Ram
-
10. května 2012 4:41
Hello Rick,
I am using TFS for Java SDK version 10.1 (com.microsoft.tfs.sdk-10.1.0.jar) which the latest available version.
I checked the de-compiled code for WorkItemImpl, the code does not seem to populate the attachmentCollection member. So I am confused if your version of WorkItemImpl class is different from mine.
Can you please provide the sdk version which you are using?
Thanks,
Ram
-
13. června 2012 14:46Moderátor
Ram-
It looks like you're using a custom control for attachments - perhaps the screenshots custom control? In this case, it appears that your server administrator has installed this custom control and replaced the standard attachments tab in the work item template.
It's important to remember that custom work-item controls are platform specific. If you develop a custom work item control, you will need to create three implementations: one for Visual Studio, one for Web Access and one for Team Explorer Everywhere. Since each uses a different UI mechanism (WinForms or WPF for Visual Studio, HTML for Web Access and Java SWT for Team Explorer Everywhere), we cannot run a single custom work-item control on all platforms. This is why you see the error message "Unsupported custom control" in the Attachments tab.
Further, since the custom control overrides the Attachments tab, and uses a custom storage mechanism (instead of using the built-in work item attachment functionality), so since it is not using the standard attachment storage, you cannot use the TFS SDK directly to get it. TFS stores attachments as part of the work item itself, which you would see as an entry in the File table of work item. It is not stored in the XML schema you've attached above.
If this is a work item custom control that you have written, or that you have the source for, you should create a compatible implementation for Team Explorer Everywhere, using the TEE SDK. If this is a third-party tool, I'm afraid you'll need to contact the vendor directly.
- Navržen jako odpověď Edward A ThomsonMicrosoft Employee, Moderator 13. června 2012 14:46
- Označen jako odpověď Shaw TerwilligerOwner 18. června 2012 13:40