Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 28, 2013 @ 16:33
    Fuji Kusaka
    0

    Take number of items in Media Folder within folders

    Hi everyone,

    i have some issues with a media folder where i need to display only 10 items within media folder.

    With a media Picker the user can choose a  media folder where there are sub folders.

    if(CurrentModel.HasProperty("rMFolder") && CurrentModel.GetProperty("rMFolder").Value != String.Empty){
    int MFolder = Convert.ToInt32(CurrentModel.GetProperty("rMFolder").Value);
        var DocumentLib = new Media(MFolder);
            
    if (DocumentLib.ChildCount > 0)
    {   

    var count =0 ;
    IEnumerable<Media> fd = DocumentLib.GetChildMedia().OrderByDescending(x => x.CreateDateTime).Where(x => x.ContentType.Alias == "Folder");
     
    foreach (var docFolder in fd)
    { if (docFolder.ChildCount > 0) { IEnumerable<Media> f = docFolder.GetChildMedia().OrderByDescending(x => x.CreateDateTime).Where(y => y.ContentType.Alias == "File");
     
    foreach(var t in f.Take(10)){
    count ++;
    @count @:-  @t.Text in @t.Parent.Text<br/>  
    }
    }
    }
    }    
    }

    But here i cant get it to display only the 10 latest items within media folders.

    Any idea why ?

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 28, 2013 @ 19:11
    Fuji Kusaka
    100

    Looks like i was in the wrong direction. This is how i should have done this

    IEnumerable<Media> fds = DocumentLib.GetDescendantMedia().Where(x => x.ContentType.Alias == "File" && x.getProperty("umbracoFile").Value != String.Empty);
Please Sign in or register to post replies

Write your reply to:

Draft