Copied to clipboard

Flag this post as spam?

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


  • Magnus Szatkowski 28 posts 149 karma points
    Aug 15, 2016 @ 11:02
    Magnus Szatkowski
    0

    Include .dll - where?

    Hi there,

    I am trying to use Media Service (https://our.umbraco.org/Documentation/Reference/Management/Services/MediaService)

    What i stumbled upon was where to include:

    "Umbraco.Core.dll"

    as it says i have to. Can anyone help me with this?

    Kind regards Magnus

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Aug 15, 2016 @ 11:07
    Nik
    0

    Hi Magnus,

    Can you explain what you are trying to do? If you are using Umbraco, the Umbraco.Core dll will already be included in your project.

    Thanks,

    Nik

  • Magnus Szatkowski 28 posts 149 karma points
    Aug 15, 2016 @ 11:37
    Magnus Szatkowski
    0

    Hi there Nik,

    Thank you for your answer.

    I am trying to make a "library" iterate the folders of a parent Media Folder called "biblioteket". For each of these folders i want to create a link into a page where the folders' name is the headline and all the PDF files in the Folder are shown as items.

    My problem seems to be in creating a parent Media file through which i can iterate.

    Is this anything you can help with?

    Thank you - Magnus

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 15, 2016 @ 12:47
    Alex Skrypnyk
    0

    Hi Magnus,

    Try to crate media folder, what exactly is the problem?

  • Magnus Szatkowski 28 posts 149 karma points
    Aug 15, 2016 @ 12:55
    Magnus Szatkowski
    0

    Hi Alex,

    I have created the media folder.

    What I want to create is a for each loop that iterates all the media elements in a folder. As far as i could see i needed to use the "MediaService" and it gave me an error. So what i have now is this:

    Eg. parent folder "Biblioteket" > "Mappe1" - "Mappe1" Then contains several .pdf files. I want to create a div for each of these pdf files which has an tag that opens the pdf file in a _blank

    see this for better understading:

    http://maggerit-development.dk/filurens-bibliotek/ + http://maggerit-development.dk/filurens-bibliotek/ny-dansk-dramatik/

    i want the "Ny Dansk Dramatik" page to load all the pdf files in a folder as the "Fil 1 test".

    Sorry if this is not well described, please feel free to ask if you dont get it. And thank you for your time!

    kind regards, Magnus

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 15, 2016 @ 15:42
    Alex Skrypnyk
    1

    Hi Magnus,

    As I understand you need something like:

    var rootMedia = Umbraco.TypedMediaAtRoot().FirstOrDefault(x => x.Name == "Biblioteket");
    foreach (var publishedContent in rootMedia.Children)
    {
        @publishedContent.Url
    }
    

    This code renders urls all medias under Biblioteket root node in media section. I hope it will help you.

    Thanks,

    Alex

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Aug 15, 2016 @ 13:36
    David Brendel
    1

    Hi Magnus,

    first of all if you just want to display media items on frontpage of your website then don't use the MediaService. It goes to the database and should not used for frontend actions.

    Have a look at the Umbraco.TypedMedia() helpers to query for media items.

    Regards David

  • Magnus Szatkowski 28 posts 149 karma points
    Aug 16, 2016 @ 08:22
    Magnus Szatkowski
    0

    Hi Alex and David,

    Both of you are leading me the right way!! Thank you! I am so close now.

    However, the code you provided Alex only iterate and display through the folders within "Biblioteket". I need the template of this node to display the content of a folder that is within the "Bibliotek".

    I have tried this, but it doesnt work:

            @{  var chosen = Umbraco.Field("vaelgMediaMappe");
            var rootMedia = Umbraco.TypedMediaAtRoot().FirstOrDefault(x => x.Name == "@chosen.Name");
            foreach (var publishedContent in rootMedia.Children)
            {
    
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 ">
                <a href="@publishedContent.Url" target"_blank">
                    <div class="to-en Border Center-Tilbud hvr-grow-shadow Info-Aside-Shadow" >
                        <img src="~/media/1104/file-pdf_128.png" alt="Mappe">
                        <h3>@publishedContent.Name</h3>
                    </div>
                </a>
            </div>
            } 
        }
    

    The "vaelgMediaMappe" is a Field of datatype Media Picker, where my future client has to choose the folder in which the pdf documents they want to show is located.

    How do i get to iterate through the files in the "vaelgMediaMappe" folder ?

    Thank you so much for your time and help,

    Kind Regards, Magnus

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 16, 2016 @ 10:05
    Alex Skrypnyk
    101

    Hi Magnus,

    Try this code, we are close:) :

    @{
        var rootFolder = Umbraco.TypedMedia(Umbraco.AssignedContentItem.GetPropertyValue("vaelgMediaMappe"));
    
        foreach (var publishedContent in rootFolder.Children)
        {
            if (publishedContent.DocumentTypeAlias.Equals("Folder"))
            {
                foreach (var publishedContentDescendant in publishedContent.Children)
                {
                    <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 ">
                        <a href="@publishedContentDescendant.Url" target="_blank">
                            <div class="to-en Border Center-Tilbud hvr-grow-shadow Info-Aside-Shadow">
                                <img src="@publishedContentDescendant.Url" alt="Mappe">
                                <h3>@publishedContentDescendant.Name</h3>
                            </div>
                        </a>
                    </div>
                }
            }
        }
    }
    

    Thanks,

    Alex

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Aug 16, 2016 @ 10:19
    Nik
    1

    Hi Magnus,

    What Alex has produced looks pretty good, however an alternative would be to create a recursive function that allows for potentially infinite depth.

    I would looks at extracting the middle of the outer foreach loop like this:

    @helper RenderMediaItem(IPublishedContent mediaNode)
    {
        if (mediaNode.DocumentTypeAlias.Equals("Folder"))
        {
            foreach (var child in mediaNode.Children)
            {
                @RenderMediaItem(child) ;
            }
        }
        else
        {
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 ">
                <a href="@mediaNode.Url" target="_blank">
                    <div class="to-en Border Center-Tilbud hvr-grow-shadow Info-Aside-Shadow">
                        <img src="@mediaNode.Url" alt="Mappe">
                        <h3>@mediaNode.Name</h3>
                    </div>
                </a>
            </div>
        }
    }
    

    Then this can be called like this:

    @{
        var rootFolder = Umbraco.TypedMedia(Umbraco.AssignedContentItem.GetPropertyValue("vaelgMediaMappe"));
        foreach(var publishedContent in rootFolder.Children){
            @RenderMediaItem(publishedContent )
        }
    

    You could extend this to limit the depth it works to as well by having a level option as IPublishedContent has a level indicator against it.

  • Magnus Szatkowski 28 posts 149 karma points
    Aug 16, 2016 @ 10:58
    Magnus Szatkowski
    0

    Hey Alex and Nik,

    IT WORKS! :D

    I tweaked Alex' code a bit in order for it to do it right, so the code is now:

        @{
            var rootFolder = Umbraco.TypedMedia(Umbraco.AssignedContentItem.GetPropertyValue("vaelgMediaMappe"));
    
                foreach (var publishedContent in rootFolder.Children)
                    {
                    if (publishedContent.DocumentTypeAlias.Equals("Folder"))
                        {
                        foreach (var publishedContentDescendant in publishedContent.Children)
                            {
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 ">
                                <a href="@publishedContentDescendant.Url" target="_blank">
                                    <div class="to-en Border Center-Tilbud hvr-grow-shadow Info-Aside-Shadow">
                                        <img src="~/media/1103/folder1_128.png" alt="Mappe i filurens bibliotek">
                                        <h3>@publishedContentDescendant.Name</h3>
                                    </div>
                                </a>
                            </div>
                            }
                        } 
                    else 
                        {
                            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-6 ">
                                <a href="@publishedContent.Url" target="_blank">
                                    <div class="to-en Border Center-Tilbud hvr-grow-shadow Info-Aside-Shadow">
                                        <img src="~/media/1104/file-pdf_128.png" alt="Fil i filurens bibliotek">
                                        <h3>@publishedContent.Name</h3>
                                    </div>
                                </a>
                            </div>
                        }
                    }
        }
    

    I can see the possibilites in your response Nik, and i will save it for further use! :D

    Thank you all very much! It has been a really big help!

    Kind regards, Magnus

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Aug 16, 2016 @ 11:00
    Alex Skrypnyk
    0

    Magnus, we are really happy to help!!!

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft