Try Now
More in this section

Forums / Developing with Sitefinity / Selecting root level images of library

Selecting root level images of library

2 posts, 0 answered
  1. Stacey
    Stacey avatar
    291 posts
    18 Oct 2012
    09 Sep 2013
    Link to this post
    I have a library called Slides that contains 5 images.  I then have a nested folder that contains 2 images.  I am looking for the best way to display only the 5 images when a user selects the Slides library via my widget designer.  Right now this is what I have that works, but I am guessing there is a better way.

    if (this.AlbumId != Guid.Empty)
                    model.AlbumId = this.AlbumId;
                    var manager = LibrariesManager.GetManager();
                    var album = manager.FindFolderById(model.AlbumId);
                    if (album.GetType() == typeof(Telerik.Sitefinity.Libraries.Model.Album))
                        model.Images = ((Telerik.Sitefinity.Libraries.Model.Album)album).Images().Where(i => i.FolderId == null
                         && i.Status == ContentLifecycleStatus.Live);
                        model.Images = manager.GetImages().Where(i => i.FolderId == album.Id && i.Status == ContentLifecycleStatus.Live);

    By default just using the Images() extension method for Albums will return all images nested or not that belong to said library. (i.e. I was getting 7 back).
  2. Jen Peleva
    Jen Peleva avatar
    568 posts
    10 Sep 2016
    12 Sep 2013
    Link to this post
    Hello Stacey,

     The approach you took is the correct one, because the difference between the top level library and the nested folders (libraries) is only that the top level library doesn't have a folderId.

    Jen Peleva
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered