Copied to clipboard

Flag this post as spam?

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


  • Andrew Hopkins 21 posts 133 karma points
    Mar 24, 2023 @ 17:00
    Andrew Hopkins
    0

    Force Download PDF hosted on umbraco cloud

    Has anyone been able to force download a PDF for example and how is it best to get the full file path?

        var link = Model.Value<Link>("pathToPDFFile");
    //var filePath = @link.Url;
    var filePath = Request.PhysicalApplicationPath + @link.Url;
    
    Response.AddHeader("Content-Type", "application/pdf");
    
    // Set the filename and attachment disposition
    Response.AddHeader("content-disposition", "attachment;filename=" + (filePath));
    Response.Write(filePath);
    
    // End the response
    Response.End();
    
  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Mar 24, 2023 @ 18:05
    Huw Reddick
    0

    Add the download attribute to the anchor tag

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Mar 24, 2023 @ 18:07
    Huw Reddick
    0

    <a href="/path/to/your/receipt.pdf" download>Download Receipt</a>

Please Sign in or register to post replies

Write your reply to:

Draft