List attachments
Leave feedback
To get a list of all attachments to a source file, follow these steps:
- Instantiate the Viewer object. Specify a file that contains attachments.
- Call the getAttachments method. It returns the attachment collection.
- Iterate through the collection.
The following code snippet shows how to get a list of attachments from the MSG file:
NoteNOTE: provided code snippet suits all format families that support attachments: emails, Outlook data files, archives, and PDF documents.
import com.groupdocs.viewer.Viewer;
import com.groupdocs.viewer.results.Attachment;
// ...
try (Viewer viewer = new Viewer("sample.msg")) {
List<Attachment> attachments = viewer.getAttachments();
System.out.println("\nAttachments:");
for (Attachment attachment : attachments) {
System.out.println(attachment);
}
}
The following image shows a sample console output:
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.