Render attachments
Leave feedback
Render attachments in the same way as any other documents.
To view attachments, follow these steps:
- Instantiate the first Viewer object. Specify a file that contains attachments.
- Call the SaveAttachment method to save the attachment (to local disk, memory stream, etc).
- Instantiate the second Viewer object. Specify the previously saved attachment.
- Specify the view options depending on the output format - HtmlViewOptions/PngViewOptions/JpgViewOptions/PdfViewOptions.
- Call the View method.
The following code snippet shows how to render attachments from the MSG file:
NoteNOTE: 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
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.