In the Episerver back office I have a content refrence that has a PDF file as its data.
On the front end (Razor view) I am using this code to output the PDF
When a user clicks this link, the PDF is opened in the browser, I want the browser to download the PDF and NOT open it in the browser. One thing I noticed is that the URL genrated is /globalassets/PDF-File-Name........ but this URL is not the URL to the actual location of the PDF file, how can I get this URL? and how can I force the browser to download the PDF rather than open it?
What do you mean that the /globalassets/PDf-- etc is not the url to the actual location? My guess is that it IS the url to the file in the Episerver media archive. What do you expect it to be?
Same as my answer on StackOverflow... just append /download to the URL and a download will be foreced (for browsers who honor this).
You can't link the file like that. You would need to have a controller or something which returns headers so browser know it should download the file. One option is to make the link to an action which returns FileResult, passing the content guid.
FileResult, passing the content guid.
/download will set those headers that will trigger a download.
Sidenote; if you append /thumbnail (or the name of another thumbnail property in your content/media type) to an image URL you will get the thumbnail.
Johan Petersson - Your answer was what I was actually after, I only wanted the "REAL" url thinking that would change the way the browser deals with it....
so adding /download worked but what I want to know is why... is that an episerver thing or just a genric thing you can do with PDFs?
Why is because Episerver sets the correct http response headers when you append /download. E.g.:
Content-Disposition: attachment; filename="filename.pdf"
You also might want to set the download attribute on the anchor, please see https://www.w3schools.com/TAGS/att_a_download.asp