1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Incorrect number of listitems returned

Incorrect number of listitems returned

4 posts, 1 answered
  1. Solomon Shaffer
    Solomon Shaffer avatar
    22 posts
    Registered:
    18 Jan 2011
    17 May 2011
    Link to this post
    I am using the API to access a list and album. I bring back all of the items and the number seems to always be incorrect. 

    For instance, I have a list with 5 list items in it. The API is returning 11. I have an album with 2 images in it. The API is returning 5 images. 

    Any thoughts on why this would be happening? I frequently did this in SF 3.x with no problems.

    Below is some commented code.

    private void BuildUpcomingTrips()
    {
        var list = GetListByName("Upcoming Trips List");
     
        //list.ListItems returns 11 items, but there are only 5 items in this list
        foreach (var listItem in list.ListItems)
        {
            items.Append(listItem.Content));
        }
    }
     
    private void BuildSlideshow()
    {
        var album = GetAlbumByName("Homepage Slideshow Images");
     
        //album.Images.ToList() returns 5 items, but there are only 2 items in this list
        foreach (var image in album.Images.ToList())
        {
            items.Append(simage.UrlName));
        }
    }
     
    private static Telerik.Sitefinity.Libraries.Model.Album GetAlbumByName(string name)
    {
        var librariesManager = LibrariesManager.GetManager();
        var albums = librariesManager.GetAlbums();
     
        return Enumerable.FirstOrDefault(albums, album => album.Title.ToLower() == name.ToLower());
    }
     
    private static Telerik.Sitefinity.Lists.Model.List GetListByName(string name)
    {
        var listManager = new Telerik.Sitefinity.Modules.Lists.ListsManager();
        var lists = listManager.GetLists();
     
        return Enumerable.FirstOrDefault(lists, list => list.Title.ToLower() == name.ToLower());
    }


  2. Solomon Shaffer
    Solomon Shaffer avatar
    22 posts
    Registered:
    18 Jan 2011
    17 May 2011
    Link to this post
    Even stranger. Without doing anything, now the album shows 4 items (not five). 
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 May 2011
    Link to this post
    Hi Solomon,

    Can you try getting only the items with status live? cnt.Status == ContentLifecycleStatus.Live. I suppose that you are returning all items and this is why there are difference in the items count.

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    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
    Answered
  4. Solomon Shaffer
    Solomon Shaffer avatar
    22 posts
    Registered:
    18 Jan 2011
    17 May 2011
    Link to this post
    That was it. Thanks, Ivan!

    I modified my code and everything is right in the world. 

    private void BuildSlideshow()
    {
        var album = GetAlbumByName("Homepage Slideshow Images");
     
        foreach (var image in album.Images.ToList().Where(image => image.Status == ContentLifecycleStatus.Live))
        {
            items.Append(image.UrlName));
        }
    }

    All, please see http://www.sitefinity.com/40/help/developers-guide/t_telerik_sitefinity_genericcontent_model_contentlifecyclestatus.html for an explanation of the various lifecycle states of a model object.
4 posts, 1 answered