Finding list items

Sitefinity allows you to search for a specific list item. For more information about querying list items by ID, see Querying list items.

To search for a specific list item you can use the Native API or the Fluent API.

Searching for a list item by title

The following examples search for a specific list item with the specified Title.

Native API

public ListItem GetListItemByTitleNativeAPI(string title)
{
    ListsManager listsManager = ListsManager.GetManager();
    ListItem listItem = listsManager.GetListItems().Where(i => (i.Title == title && i.Status == ContentLifecycleStatus.Live))
        .FirstOrDefault();
    return listItem;
}

First, you initialize ListsManager. Then, you get all list items using GetListItems() and filter based on the Title and Status properties. Finally, you return the list item.

Fluent API

public ListItem GetListItemByTitleFluentAPI(string title)
{
    ListItem listItem = App.WorkWith().ListItems().Where(i => (i.Title == title && i.Status == ContentLifecycleStatus.Live))
        .Get().FirstOrDefault();
    return listItem;
}

First, you initialize the plural facade of the list item using App.WorkWith().ListItems(). Then, you filter based on the Title and Statusproperties. To get the list item, you use the Get method. Finally, you return the list item.

See Also

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK