user2791953
user2791953

Reputation: 21

How to filter SharePoint listitems with PnP Core SDK

I'm unable to find a good example of reading sharepoint listitems and filtering on a custom column with the PNP.Core sdk library in C#.

I could filter on Title:

                var listItems = await pnpContext.Web.Lists.GetByTitle("TestList")
                    .Items
                    .Where(x => x.Title == "Foo" )
                    .ToListAsync();

But I would need something like this:

                var listItems = await pnpContext.Web.Lists.GetByTitle("TestList")
                    .Items
                    .Where(x => x["Status"] == "Completed" )
                    .ToListAsync();

The result api call should look like this (or the corresponding graph api call): _api/web/lists/getByTitle('TestList')/items/?$filter=Status eq 'Completed'

Upvotes: 0

Views: 670

Answers (1)

ChengFeng - MSFT
ChengFeng - MSFT

Reputation: 141

I checked the documentation, https://pnp.github.io/pnpcore/using-the-sdk/listitems-intro.html Maybe you can do this

var listItems = await context.Web.Lists.GetByTitle("TestList")
    .Items
    .Where(x => x.Values["Status"].ToString() == "Completed")
    .LoadAsync();

enter image description here

Upvotes: 1

Related Questions