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:
Note
NOTE: provided code snippet suits all format families that support attachments: emails, Outlook data files, archives, and PDF documents.
usingSystem;usingSystem.Collections.Generic;usingGroupDocs.Viewer;usingGroupDocs.Viewer.Results;// ...using(Viewerviewer=newViewer("sample.msg")){// Get list of attachments.IList<Attachment>attachments=viewer.GetAttachments();// Display list of attachments.Console.WriteLine("\nAttachments:");foreach(Attachmentattachmentinattachments)Console.WriteLine(attachment);}
ImportsSystemImportsSystem.Collections.GenericImportsGroupDocs.ViewerImportsGroupDocs.Viewer.Results' ...
ModuleProgramSubMain(argsAsString())UsingviewerAsViewer=NewViewer("sample.msg")' Get list of attachments.
DimattachmentsAsIList(OfAttachment)=viewer.GetAttachments()' Display list of attachments.
Console.WriteLine(Global.Microsoft.VisualBasic.Constants.vbLf&"Attachments:")ForEachattachmentAsAttachmentInattachmentsConsole.WriteLine(attachment)NextEndUsingEndSubEndModule
sample.msg is the sample file used in this example. Click here to download it.
Attachments:
invoice-NWR-2026-0912.pdf - Portable Document Format File (.pdf); ID: beef1f0b-cf7a-5f11-9a96-c45164d87592; Path: invoice-NWR-2026-0912.pdf; Size: 198531B
delivery-note-0912.xlsx - Microsoft Excel Open XML Spreadsheet (.xlsx); ID: 27d8bb8f-7c88-592f-8967-72831e28e818; Path: delivery-note-0912.xlsx; Size: 7643B