Copied to clipboard

Flag this post as spam?

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


  • J 445 posts 862 karma points
    Nov 20, 2017 @ 17:07
    J
    0

    Get document URL from Media folder

    I upload a file within the media section.

    I have created a Document Type which allows me to choose a document from the Media folder, for the page i have created. I can have multiple pages.

    When a user arrives at this page they wont see the document i uploaded above (as i would have hidden it from displaying at this stage).

    What i would like to do is when they click the download button to take them to another page, gather some information and then allow them to download the document tied to this page.

    I am using a custom control and wonder how i could get the download URL for the page/document they visited (mainly for the document that was uploaded, so once i have their info i can initiate a download)?

  • Jan A 58 posts 263 karma points
    Nov 21, 2017 @ 12:56
    Jan A
    100

    My advice would be to pass in the page id (or media id) to the form. Let user enter data and then when form is submitted return the file as an File object. Otherwise the exposed url will download the file even if you don't submit the additionally data.

    But to get the url and filepath

    int nodeId = 1234; // get this from wherever!
    var media = new umbraco.cms.businesslogic.media.Media(nodeId);
    var url = media.Url;
    var file = media.getProperty("umbracoFile");
    string filePath = file.Value;
    

    Some ref to return file as an document that will be downloaded etc.

    https://our.umbraco.org/forum/developers/api-questions/70058-media-file-download-handler

    https://stackoverflow.com/questions/3604562/download-file-of-any-type-in-asp-net-mvc-using-fileresult

Please Sign in or register to post replies

Write your reply to:

Draft