List attachments

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Viewer MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-viewer -- dnx GroupDocs.Viewer.Mcp --yes
Folders, licensing and more →

To get a list of all attachments to a source file, follow these steps:

  1. Instantiate the Viewer object. Specify a file that contains attachments.
  2. Call the GetAttachments method. It returns the attachment collection.
  3. 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.
using System;
using System.Collections.Generic;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Results;
// ...

using (Viewer viewer = new Viewer("sample.msg"))
{
    // Get list of attachments.
    IList<Attachment> attachments = viewer.GetAttachments();

    // Display list of attachments.
    Console.WriteLine("\nAttachments:");
    foreach (Attachment attachment in attachments)
        Console.WriteLine(attachment);
}
Imports System
Imports System.Collections.Generic
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Results
' ...

Module Program
    Sub Main(args As String())
        Using viewer As Viewer = New Viewer("sample.msg")
            ' Get list of attachments.
            Dim attachments As IList(Of Attachment) = viewer.GetAttachments()
        
            ' Display list of attachments.
            Console.WriteLine(Global.Microsoft.VisualBasic.Constants.vbLf & "Attachments:")
            For Each attachment As Attachment In attachments
                Console.WriteLine(attachment)
            Next
        End Using
    End Sub
End Module

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

Download full output