Render attachments

Render attachments in the same way as any other documents.

To view attachments, follow these steps:

  1. Instantiate the first Viewer object. Specify a file that contains attachments.
  2. Call the SaveAttachment method to save the attachment (to local disk, memory stream, etc).
  3. Instantiate the second Viewer object. Specify the previously saved attachment.
  4. Specify the view options depending on the output format - HtmlViewOptions/PngViewOptions/JpgViewOptions/PdfViewOptions.
  5. Call the View method.

The following code snippet shows how to render 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.IO;
using GroupDocs.Viewer;
using GroupDocs.Viewer.Options;
using GroupDocs.Viewer.Results;
// ...

// Specify attachment.
Attachment attachment = new Attachment("attachment-word.doc", @"C:\Output\attachment-word.doc");

// Create a stream for attachment.
MemoryStream attachmentStream = new MemoryStream();

//Save attachment
using (Viewer viewer = new Viewer("sample.msg"))
{
    viewer.SaveAttachment(attachment, attachmentStream);
}

// Render attachment
using (Viewer viewer = new Viewer(attachmentStream))
{
    HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources();
    viewer.View(options);
}
Imports System.IO
Imports GroupDocs.Viewer
Imports GroupDocs.Viewer.Options
Imports GroupDocs.Viewer.Results
' ...

Module Program
    Sub Main(args As String())
        ' Specify attachment.
        Dim attachment As Attachment = New Attachment("attachment-word.doc", "C:\Output\attachment-word.doc")
    
        ' Create a stream for attachment.
        Dim attachmentStream As MemoryStream = New MemoryStream()
    
        'Save attachment
        Using viewer As Viewer = New Viewer("sample.msg")
            viewer.SaveAttachment(attachment, attachmentStream)
        End Using
    
        ' Render attachment
        Using viewer As Viewer = New Viewer(attachmentStream)
            Dim options As HtmlViewOptions = HtmlViewOptions.ForEmbeddedResources()
            viewer.View(options)
        End Using
    End Sub
End Module