Copied to clipboard

Flag this post as spam?

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


  • Richard Green 6 posts 88 karma points
    Dec 07, 2016 @ 11:57
    Richard Green
    0

    Manage Downloads Folder via Back Office

    Hi all,

    In Umbraco, I'm using the Media folder as you would expect for page images but I would also like to have another folder where I can put .pdf and other documents for visitors to download from a /downloads path.

    Currently, I have the folder on the web server and I upload files to the /downloads path manually via FTP but it would be great if there was a way I could handle this via Back Office in Umbraco instead of using FTP.

    Is this possible and if so, can anyone point me in the right direction?

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Dec 07, 2016 @ 13:44
    Dennis Adolfi
    1

    Hi Richard.

    Here is one way of solving this:

    Create a folder in your Media section called "Downloads".

    enter image description here

    Then Create a DocumentType (with a Template) called "Downloads" with a Media Picker property called "Media Folder".

    enter image description here

    Now create a page called "Downloads" with this new DocumentType in your content area.

    enter image description here

    Now this page will get the URL /downloads. In your Downloads.cshtml file that you created, paste the following code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<IPublishedContent>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = null;
    
        var mediaFolder = Model.Content.GetPropertyValue<int>("mediaFolder");
    }
    
    @if (mediaFolder != 0)
    {
        var mediaFolderItem = Umbraco.TypedMedia(mediaFolder);
        if (mediaFolderItem != null)
        {
            <ul>
                @foreach (var childMedia in mediaFolderItem.Children)
                {
                    <li>
                        <a href="@childMedia.Url" download="@childMedia.Name">@childMedia.Name</a>
                    </li>
                }
            </ul>
        }
    }
    

    (This can probobly be made nicer, but it gives you an idea.)

    Result:

    enter image description here

    Hopefully this gives you an idea. Make sure that pdf files are not in the disallowedUploadFiles list in /Config/umbracoSettings.config file.

    Also if you want your files URL to look like /downlods/examplefile.txt instead of the standard /media/mediaId/examplefile.txt, this is totally doable. You need to do your own custom UrlProvider and ContentFinder. Luckily there is this great tutorial on how to do this: http://24days.in/umbraco-cms/2014/urlprovider-and-contentfinder/

    Best of luck to you!!

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    Dec 13, 2016 @ 18:15
    Dennis Adolfi
    0

    Hi Richard.

    Did you try the above or did you come up with a solution yourself?

    Would you like to share your solution so that it might help others?

    All the best! / Dennis

Please Sign in or register to post replies

Write your reply to:

Draft