Copied to clipboard

Flag this post as spam?

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


  • Naveed Ali 161 posts 426 karma points
    Apr 22, 2016 @ 14:31
    Naveed Ali
    0

    Uploading PDF's

    Hi I am fairly new to umbraco 7. I need to create a download links menu on a page which has links to PDF documents.

    I have tried doing some searching and can see either to use media picker or file upload.

    file upload is no good as I need to be able to select multiple documents and the media picker does not seem to work, as it gets the pdf document as an image picker.

    any one have a link to any documentation on this, preferably to do it dynamically

    Thanks

    Nav

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Apr 24, 2016 @ 08:40
    Marc Goodson
    1

    Hi Naveed

    Yes, a multiple media picker is the correct approach, and in the past this has allowed you to pick and upload multiple documents (not necessarily images) for sections such as you describe.

    However a recent introduction to allow the media picker to be restricted to images only, configurable on the datatype, has caused a few issues:

    issues.umbraco.org/issue/U4-8016

    but it seems in 7.4.3 you can pick PDFs again!

    regards

    Marc

  • Naveed Ali 161 posts 426 karma points
    Apr 24, 2016 @ 18:23
    Naveed Ali
    0

    hi thanks for the reply, I have just checked and I am using 7.4.3..

    this is my razor code in the view:

    @using wodc.code;
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        if (CurrentPage.HasValue("downloadLinks"))
    {    
        <div class="grey-wrapper">
            <div class="header clearfix">
                <h3>@UmbracoHelpers.getValue("lblDownloads")</h3>
            </div>
            <div class="content round-5">
                <ul class="coloured-box-downloads-content">
                    @foreach (var d in CurrentPage.DownloadLinks)
                    {
                    try
                    {
                        var file = CurrentPage.MediaById(d.InnerText);
                        if (!UmbracoHelpers.isRecycled(file))
                        {
    
                            float fileBytes;
                            float kb = (float.TryParse(file.umbracoBytes, out fileBytes) ? fileBytes : 0) / 1024;
                            double rounded = Math.Round((double)kb, 1);
                            string fileSize = @kb > 0 ? @rounded + " KB" : "Unknown";
                            // UmbracoHelpers.GetFormattedDownloadName(file)
                        <li><a href="@file.Url" target="_blank">@file.Name <span class="grey-txt">(@file.umbracoExtension.ToUpper() - @fileSize)</span></a></li>
                        }
                    }
                    catch (Exception ex)
                    {
    
                    }
                }
            </ul>
        </div>
    </div>
    

    } }

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Apr 24, 2016 @ 18:54
    Marc Goodson
    0

    Hi Naveed

    Try replacing your line

     @foreach (var d in CurrentPage.DownloadLinks)
    

    with

      @{ 
                        var relatedMediaList = CurrentPage.DownloadLinks;
                        var relatedMediaIds = relatedMediaList.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        var relatedMedia = Umbraco.Media(relatedMediaIds);
                    }
                    @foreach (var file in relatedMedia)
    

    (and remove your line: var file = CurrentPage.MediaById(d.InnerText);)

    I've broken this down so you can see what is happening, the Media Picker, stores a comma delimited list of the ids of the picked media, and Umbraco.Media has an overload that excepts a string array of ids and then returns an enumerable of the media items. So you can just loop through those and the rest of your code should work...

    regards

    Marc

  • Naveed Ali 161 posts 426 karma points
    Apr 24, 2016 @ 21:07
    Naveed Ali
    0

    Thanks for the help.. I have replaced the code..but still cant get it to work.. What data type should I be using??

  • Marc Goodson 2157 posts 14434 karma points MVP 9x c-trib
    Apr 24, 2016 @ 23:52
    Marc Goodson
    101

    Hi Naveed

    A Multiple Media Picker.

    Here is the full code of the macro partial:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        if (CurrentPage.HasValue("downloadLinks"))
        {
            <div class="grey-wrapper">
                <div class="header clearfix">
                    <h3>Downloads</h3>
                </div>
                <div class="content round-5">
                    <ul class="coloured-box-downloads-content">
                        @{ 
                            var relatedMediaList = CurrentPage.DownloadLinks;
                            var relatedMediaIds = relatedMediaList.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            var relatedMedia = Umbraco.Media(relatedMediaIds);
                        }
                        @foreach (var file in relatedMedia)
                        {
                            try
                            {
                                             if (file.DocumentTypeAlias == "File")
                                {
    
                                    float fileBytes;
                                    float kb = (float.TryParse(file.umbracoBytes, out fileBytes) ? fileBytes : 0) / 1024;
                                    double rounded = Math.Round((double)kb, 1);
                                    string fileSize = @kb > 0 ? @rounded + " KB" : "Unknown";
                                    // UmbracoHelpers.GetFormattedDownloadName(file)
                                    <li><a href="@file.Url" target="_blank">@file.Name <span class="grey-txt">(@file.umbracoExtension.ToUpper() - @fileSize)</span></a></li>
                                }
                            }
                            catch (Exception ex)
                            {
    
                            }
                        }
                    </ul>
                </div>
            </div>
        } }
    

    So if I pick some pdfs enter image description here

    this is the result of the macro: enter image description here

  • Naveed Ali 161 posts 426 karma points
    Apr 25, 2016 @ 08:28
    Naveed Ali
    0

    Thank You so much that is working perfectly now :-)

    I will mark the answer so other people can find the solution too

    Again thank you a lot

  • Manish 373 posts 932 karma points
    Apr 28, 2016 @ 11:56
    Manish
    0

    Yes, go with macro is good solution

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies