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:
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> } }
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>
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
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
Thank you.
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.
is working on a reply...