Free Support Forum - groupdocs.com

Attachments within attachments

Hi,

Can you please tell me how to change the viewer (Angular version at https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET-MVC-App/tree/master/Viewer-Modren-UI) to display all the attachments recursively?

E.g. Email A has attachments B and C - B is an email with attachments B1 and B2. I’d expect the viewer to show pages A (email body), B (email body), B1 (attachment to B), B2 (attachement to B) and C in that order.

The latest commit (pulled today: commit ID e4284552) doesn’t do it.

@dbaker1,

Thanks for using GroupDocs.Viewer and posting to our forum.

Would you please also share with us the sample email message containing attachments in the same way you have mentioned above? We shall be looking forward to your response.

Please find an example attached. I tried it on the https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET-MVC-App/tree/master/Viewer-Modren-UI and it threw an exception when rendering Email B.Email A.zip (125.9 KB)

@dbaker1,

Thanks for sharing the sample email message.

You are getting the exception because the attachment Email B - with attachments doesn’t contain the extension (see this). You can try rendering the attachment without extension using one of the following solutions:

foreach (AttachmentBase attach in docinfo.Attachments)
{
   using (FileContainer file = htmlHandler.GetFile(attach))
   {
       //SOLUTION 1: Save file to storage and get pages if you do know file extension
       string fileName = ReplaceInvalidFileNameChars(file.FileName + ".msg");
       string filePath = Path.Combine(config.StoragePath, fileName);
       
       using (FileStream fs = new FileStream(filePath, FileMode.Create))
             file.Stream.CopyTo(fs);    
       
       List<PageHtml> pages = htmlHandler.GetPages(fileName);

       //SOLUTION 2: Or try get pages from stream
       /*
       List<PageHtml> pages = htmlHandler.GetPages(file.Stream);
       */
   }
}

private static string ReplaceInvalidFileNameChars(string fileName)
{
     return string.Join("_", fileName.Split(Path.GetInvalidFileNameChars()));
}

Furthermore, we have logged your request to render the attachments recursively in our GitHub issues as https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET-MVC-App/issues/29. We shall investigate your scenario further to provide its solution.

Thanks for that Usman,

Looking at your suggestion gave me a clue for the modern UI code issue - similar code to that is in the AttachmentHtmlController.Get() function.

If I comment out the part that checks if the attachment directory exists in the cache and let it use the ‘else’ part:

    foreach (AttachmentBase attachmentBase in docInfo.Attachments.Where(x => x.Name == attachment))
    {
        // Get attachment document html representation
        List<PageHtml> pages = handler.GetPages(attachmentBase, o);
        foreach (PageHtml pageHtml in pages.Where(x => x.PageNumber == page)) { fullHtml += pageHtml.HtmlContent; };
    }

It gets past the missing extension issue but I still only see three pages:
Email nested attachments missing.pdf (328 KB)

I should be seeing 6 pages (because attachement B has 2 docx attachments).

Thanks again,
Darryl.

@dbaker1,

Thanks for your response.

You are getting only three pages beacuse the feature of rendering attachment within the attachment is not implemented in the application. Therefore, the attachments of B are not getting rendered. We have logged your request in our GitHub issues as https://github.com/groupdocs-viewer/GroupDocs.Viewer-for-.NET-MVC-App/issues/29 for the implementation of this feature. We shall keep you informed in case of any updates.

Do you have an example of rendering attachments within attachments in any of the other demo apps?

@dbaker1,

Thanks for coming back to us.

I am afraid that the feature of rendering attachments within the attachment is not implemented in any of our demo applications. However, as soon as we get any updates regarding the implementation of this feature, we shall notify you. We appreciate your patience in this regard.