How to convert and view attachments
View email/file attachments in the same way as you would view any other documents.
There are many different use cases when you need to view/preview attachments form an emails, save attachments to specific location, parse or extract attachments. So we made this process easy and simple with GroupDocs.Viewer for .NET API.
GroupDocs.Viewer supports attachments from following formats:
- Email attachments
- Outlook attachments
- Archives
To view attachments just follow steps below:
- Instantiate Viewer object for the file that contains attachment(s);
- Call SaveAttachment method and save attachment (to local disk, memory stream, etc);
- Instantiate new Viewer object with previously saved attachment;
- Specify view options depending on desired output format - HtmlViewOptions / PngViewOptions / JpgViewOptions / PdfViewOptions;
- Call View method.
Following code snippet demonstrates on how to view attachments from MSG file.
Attachment attachment = new Attachment("attachment-word.doc");
MemoryStream attachmentStream = new MemoryStream();
using (Viewer viewer = new Viewer("sample.msg"))
{
viewer.SaveAttachment(attachment, attachmentStream);
}
using (Viewer viewer = new Viewer(() => attachmentStream))
{
HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources();
viewer.View(options);
}
More resources
Advanced Usage Topics
To learn more about document viewing features, please refer to the advanced usage section.
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for .NET examples, plugins, and showcase
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET MVC UI Example
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.