More in this section
Forums / Developing with Sitefinity / Selecting root level images of library

Selecting root level images of library

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
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 Nov 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