An ‘attachment’ is a file such as a document or a photo that is attached to an email. It’s easy to attach pictures, files, contacts, emails and many other items to your Outlook messages. If you selected a file on your local computer or group document library for the attachment purpose, a copy of the file is attached to the email.

The case: A software developer is making a document viewing application. Although, his application is capable to render the MS Outlook Emails, but he also wants to add a feature to render the email attachments.

The GroupDocs.Viewer for .NET API for Processing Attachments

The GroupDocs.Viewer for .NET API provides the functionality to process attachments from document types that support them, e.g. Email documents, Outlook data files, Archives and PDF documents.

You’ll see in the below sections that how we can process the Microsoft Outlook Email attachments in various ways.

Render document attachments

To achieve this by using GroupDocs.Viewer for .NET you should:

  • Instantiate _Viewer _object for the initial document that contains attachment;
  • Call _SaveAttachment _method and save attachment somewhere (for example, to local disk or memory stream);
  • Instantiate another one V_iewer _object and path saved attachment to it;
  • Specify view options dependent on desired output format - HtmlViewOptions / PngViewOptions / JpgViewOptions / PdfViewOptions;
  • Call View method and render an attachment.

Following example demonstrates how to render document attachments.

Retrieve and print document attachments

GroupDocs.Viewer enables you to retrieve and print document attachments. The steps to get the list of all attachments are given below:

  • Instantiate _Viewer _object for the initial document that contains attachment;
  • Call Get_Attachments _method and obtain collection of document attachments ;
  • Iterate through attachments collection and print attachment names.

Following example demonstrates the implementation of the above steps.

Save document attachments

GroupDocs.Viewer enables you save document attachments to stream. Here are the steps for saving attachments:

  • Instantiate _Viewer _object for the initial document that contains attachment;
  • Call Get_Attachments _method and obtain collection of document attachments ;
  • Iterate through attachments collection and save attachment calling Save_Attachment _method.

Following example demonstrates how to retrieve and save attachments.

The API offers many other handful features for your viewing applications. For more details, please feel free to visit documentation. To explore more examples you can access our open source examples and in case you would have any query, please feel to contact us using our forum.