Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Download Attachments via Code

Posted on by 70

Hi All,

We have a custom entity called Documents which is used to store attachments of various formats (PDF, Word, txt, etc.). There is a custom iFrame on our Dashboard which displays grid of these document records. Now we need to allow the user to download the document attachments directly from this grid without opening the individual Document record and then click on the attachment file. The custom iFrame grid will have a Download button, clicking on which should download the attachment directly in browser.       

My initial thought was that this implementation would be similar to how we open any form, view, dialog or report in CRM (by generating a dynamics URL) but it doesn't look that easy for attachments. Kindly provide your inputs on this.

Note:

1. I found this article on MSDN which discusses downloading attachment via plugin code. One option I can think of is to have similar logic written in a custom Action via code and call this Action when the Download button is clicked. 

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Download Attachments via Code

    Hi Ashish,

    I have a similar requirement. I have to show the notes attachment(pdf, excel, word) in an iframe on the form.

    Could you guide how we can display the pdf or excel in iframe and if it is possible?

  • Verified answer
    ashishtrivedi Profile Picture
    ashishtrivedi 70 on at
    RE: Download Attachments via Code

    Thanks all for your inputs. For any future references coming to this thread, I took the approach of querying the 'annotation' entity from Javascript using WebAPI. This WebAPI query will fetch the 'documentbody' and 'mimetype' attributes of the 'annotation' entity record which can then be parsed in Javascript to render it on client browser as the actual document (PDF, Word, etc). This solution works well for both browser and iPad versions of CRM.  

    Note that although I implemented this functionality on Javascript side, it can be achieved on the similar lines from C# code by querying the 'annotation' entity and parsing the results.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Download Attachments via Code

    There are some resource available. You can refer to this to see if it helps.

    mahadeomatre.blogspot.com.au/.../view-or-download-attachments-for.html

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Download Attachments via Code

    Hi,

    Please refer the community thread below.

    community.dynamics.com/.../179264

    Hope this helps.

  • ashishtrivedi Profile Picture
    ashishtrivedi 70 on at
    RE: Download Attachments via Code

    Hey Alex.. I am not sure whether this solution would work for all kind of attachment formats and all devices.

    Any inputs on the Action approach?

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Download Attachments via Code

    Hi,

     you might try this:

    community.dynamics.com/.../downloading-dynamics-crm-attachments-with-javascript

     I'm not sure if it's fully "supported" because attachments have never been fully supported on the scripting side in Dynamics, so use at your own risk

    EDIT: Just realized there is a missing download.js library there, so I'm not sure you can use it as is

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans