Copied to clipboard

Flag this post as spam?

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


  • Arulkumar Subramaniam 12 posts 62 karma points
    Dec 03, 2013 @ 15:52
    Arulkumar Subramaniam
    0

    Sub Folder Name in Media Library

    Hi 

    I am trying to create a Media Library and list the documents in a specified Media folder . The following code (Partial View) works very well . But it doesnt display any sub folders . How do i get the list of sub folders to be displayed as well

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @if (Model.MacroParameters["mediaID"] != null)

    {

    var mediaFolder = Umbraco.Media(Model.MacroParameters["mediaID"]);

    if(mediaFolder.Children.Any())

    {

    <ul class = "thumbnails">

    @foreach ( var mediaItem in mediaFolder.Children)

    {

    <li >

    <a href = "@mediaItem.umbracoFile" > @mediaItem.Name </a>

    </li>

    }

    <br>

    </ul>

    }

    }

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 03, 2013 @ 17:01
    Fuji Kusaka
    0

    you could try doing something like 

    foreach(dynamic folder in mediaFolder.Descendants("Folder")){
    @folder.Name
    }

     

  • Arulkumar Subramaniam 12 posts 62 karma points
    Dec 04, 2013 @ 12:55
    Arulkumar Subramaniam
    0

     Thanks Fuji

    Unfortunately it didnt work . I have created the sub folder as a media type from the main folder . I clicked on Main folder , clicked on Create and chose Folder as a Media Type

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 04, 2013 @ 13:24
    Fuji Kusaka
    0

    Can you try something like this instead ?

     

    dynamic mediaFolder = new DynamicMedia(MediaID);
    if(mediaFolder.Children.Any()){
    foreach(dynamic mediaItem in mediaFolder.Children){
    if(mediaItem.Where("NodeTypeAlias == \"Folder\"")){
    @mediaItem.Name // Here you can make another loop if there is any Image in the Folder
    }
    if(mediaItem.Where("NodeTypeAlias == \"Image\"")){
    <li>
    <a href = "@mediaItem.umbracoFile" > @mediaItem.Name </a>
    </li>
    }
    }
    }
  • Arulkumar Subramaniam 12 posts 62 karma points
    Dec 04, 2013 @ 14:03
    Arulkumar Subramaniam
    0

    Thanks Fuji

    This bit of line is causing issues ..not sure why

    dynamic mediaFolder1 = new DynamicMedia(1293);

     If i use this there's no error but the folders are not coming up

    dynamic mediaFolder1 = Umbraco.Media(Model.MacroParameters["mediaID"]);

    Infact when i do @mediaFolder1.Children.Count() , it shows me only the count of the files and folder's not included in the count

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 04, 2013 @ 15:41
    Fuji Kusaka
    0

    So if you do this it should display both files and folders

    if(mediaFolder.Children.Any()){
    int childrenNumber =  @mediaFolder.Children.Count();  
    @childrenNumber // Here you should be getting the number of files and folders present .
    foreach(dynamic mediaItem in mediaFolder.Children){
    @mediaItem.Name
    }
    }
  • Arulkumar Subramaniam 12 posts 62 karma points
    Dec 04, 2013 @ 17:22
    Arulkumar Subramaniam
    0

    Hi Fuji

    As i have already stated , if i do @mediaFolder1.Children.Count()  , it shows me only the 2 files

    Do you think if i assign it to variable , it should show me the folder as well. 

    No it didnt ..

    This

    int childrenNumber =  mediaFolder1.Children.Count();   

    @childrenNumber

    Still shows the count as 2 . I have 2 files and 1 folder

     

     

     

     

     

     

     

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 04, 2013 @ 21:57
    Jeavon Leopold
    0

    Hi Arulkumar,

    Can you please check that your folder has saved by clicking on the properties tab to show the save button and then clicking the save button, I was able to replicate your scenario only by not clicking the save button as it is not shown on the default contents tab.

    Jeavon

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 04, 2013 @ 21:58
    Jeavon Leopold
    0

    Your original Razor Macro Partial View does not have any issue and works perfectly once you have saved the sub folder.

  • Arulkumar Subramaniam 12 posts 62 karma points
    Dec 05, 2013 @ 10:44
    Arulkumar Subramaniam
    100

    Thanks Jeavon . It worked

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 05, 2013 @ 11:04
    Jeavon Leopold
    0

    Great, I can't quite decide if this is a bug or not. Creating a media item is creating a unpublished item, then clicking save publishes it, but of course media doesn't have a unpublished/published state....?

  • Jamie Attwood 206 posts 500 karma points c-trib
    Jan 12, 2015 @ 22:54
    Jamie Attwood
    0

    I just encountered this one as well in 6.2.2. Unexpected behaviour. I am looping through all decendants("Image") and trying to pull up all images from sub folders. Decendants("Image") won't go into any folder until you manually save each folder. I'm now looking at how to save 400+ folders without doing this all manually. It would be nice to see a little more love put into the media section (such as right context menu publish or save with children, etc). 

    Can anyone point me to a save command that I can execute via a razor for each?

    Thanks!

    Jamie

Please Sign in or register to post replies

Write your reply to:

Draft