Copied to clipboard

Flag this post as spam?

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


  • Rocoeh 65 posts 86 karma points
    Jun 25, 2012 @ 13:06
    Rocoeh
    0

    Library.MediaById not working

    If I use 

    var pics = Library.NodeById(1802);

    This works but when I try var pics = Library.MediaById(Galleries.Weddings); I get an umbraco razor file not loaded when weddings is a folder in the galleries folder in the main media folder. It works but would be more better if I could just refernece them by name.

    @{
           
            var pics = Library.NodeById(1802);

             foreach(var item in pics.Children)
                     {
                        
                        <img src="@item.umbracoFile" />

                     
                        }
            
                    
                }

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 25, 2012 @ 14:46
    Dan Diplo
    0

    I normally do something like this to ensure the node is a folder and then only get child nodes that are images:

    dynamic mediaFolder = Library.MediaById(1802);
    
    if (mediaFolder.NodeTypeAlias == "Folder")
    {
        var images = mediaFolder.Children.Where("NodeTypeAlias == \"Image\"");
    
        if (images != null && images.Count() > 0)
        {
            foreach (dynamic images in images)
            {
                 <img src="@image.umbracoFile" alt="@image.Name" />
            }
        }
    }

     

  • Carlos 338 posts 472 karma points
    Jun 25, 2012 @ 22:35
    Carlos
    0

    @Rocoech

    Try something like this. Not sure if it is what you want.  but this is what we do.

    @{

             foreach(var item in  Library.MediaById(Galleries.Weddings).Children {   
    <img src="@item.umbracoFile" />
     } 
    }
  • 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