Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Brian 77 posts 251 karma points
    Oct 30, 2014 @ 15:47
    Brian
    0

    Link media to a front end 'download' button

    Hi all,

    Trying to sort something which I'm sure is really simple but cannot get my head around it.  I have a button on one of my pages that when a visitor clicks it a PDF is downloaded.  This PDF will change for each page (they are EPC's for houses!) so I want the site administrator to select the location of the PDF from the media folder.  I was hoping it would be as simple as using media picker for my datatype and then including this in the URL (see below for code) alas all this does is send me the node for the media item.

    Please could somebody enlighten this dullard in what I am pretty sure is a simple task to do.

    Here is the code to do for the button in question:

    <a href="@Umbraco.Field("ePCDocument",  encoding: RenderFieldEncodingType.Url)" target="_blank"><li>Download EPC<img src="/images/buttons/epc.png"/></li></a>

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 30, 2014 @ 16:22
    Dennis Aaen
    101

    HI Brian,

    As I understand your question, you need to be able to link to to a pdf file from the media section. As you say you could use the media picker as the data type to let the user pick the PDF´s files in the media section

    The way I would print out the download link is by creating a parial view or a partial view macro, in this you need to place the code pull out data.

    By using  this you should get the the link to the file that are asigned to the media picker on the page that you are viewing.

    @{      
        if (CurrentPage.HasValue("ePCDocument")){                                        
            var dynamicMediaItem = Umbraco.Media(CurrentPage.ePCDocument);
            <a href="@dynamicMediaItem.umbracoFile" target="_blank">
                <li>
                    Download EPC <img src="/images/buttons/epc.png"/>
                </li>
            </a>
        }
    }

    In my example am using the dynamic razor, you could also use strongly typed razor. For the strongly typed version take look at the documentation for the media picker http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker

    Hope this helps,

    /Dennis

  • Ashish 1 post 71 karma points
    Aug 07, 2015 @ 11:34
    Ashish
    0

    Hi Dennis,

    Could you please let us know how we can achieve "Download All" functionality?

    We have to provide a button "Download All", and on click of this button we should able to download multiple files.

    Thanks, Ashish R

  • Naufil 23 posts 114 karma points
    Jul 26, 2018 @ 06:38
    Naufil
    0

    Thank you.

  • Brian 77 posts 251 karma points
    Oct 30, 2014 @ 16:54
    Brian
    0

    Thanks Dennis,

    Took me a little while to sort out as I'd never used Partial View Macros before but that worked an absolute treat!

    Thanks very much.

Please Sign in or register to post replies

Write your reply to:

Draft