Incorrect number of listitems returned

Posted by Community Admin on 04-Aug-2018 09:51

Incorrect number of listitems returned

All Replies

Posted by Community Admin on 17-May-2011 00:00

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());


Posted by Community Admin on 17-May-2011 00:00

Even stranger. Without doing anything, now the album shows 4 items (not five). 

Posted by Community Admin on 17-May-2011 00:00

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

Posted by Community Admin on 17-May-2011 00:00

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.

This thread is closed