LoadAsync() inside PnP core sdk will only get 100 list items instead of getting all items as per the documentation

40 Views Asked by At

I have this .net 8.0 console application and i am trying to get all sharepoint list items (around 20,000) using the LoadAsync method, as follow:-

static async Task Main(string[] args)
{
var tenantId = "";
var clientId = "";
var certificatePath = @"c:\CERT*.pfx";
var certificatePassword = "**";

// Initialize a new service collection
var serviceCollection = new ServiceCollection();

// Load the certificate
var certificate = new X509Certificate2(certificatePath, certificatePassword, X509KeyStorageFlags.Exportable);

// Configure logging
//serviceCollection.AddLogging(builder =>
//{
//    builder.AddConsole();
//});

// Add and configure PnP Core SDK
serviceCollection.AddPnPCore(options =>
{
    options.PnPContext.GraphFirst = true; // Set true if you prefer to use Graph over CSOM when possible
   // options.HttpRequests.UserAgent = "ISV|Contoso|ProductX";
    options.Sites.Add("SiteToWorkWith", new PnPCoreSiteOptions
    {
        SiteUrl = "https://******.sharepoint.com/sites/******",
        AuthenticationProvider = new X509CertificateAuthenticationProvider(clientId, tenantId, certificate)
    });
});

// Build the service provider
var serviceProvider = serviceCollection.BuildServiceProvider();

// Use the service provider to get the IPnPContextFactory instance
var pnpContextFactory = serviceProvider.GetRequiredService<IPnPContextFactory>();

// Now you can use the IPnPContextFactory to get a PnPContext and perform operations
var context = await pnpContextFactory.CreateAsync("SiteToWorkWith");
// Assume the fields where not yet loaded, so loading them with the list
var workOrderList = await context.Web.Lists.GetByTitleAsync("Work Orders", p => p.Title,
                                                     p => p.Fields.QueryProperties(p => p.InternalName,
                                                                                   p => p.FieldTypeKind,
                                                                                   p => p.TypeAsString,
                                                                                   p => p.Title));
await workOrderList.LoadAsync(p => p.Items);
var inMemoryWorkOrderList = workOrderList.Items.AsRequested();

but the inMemoryWorkOrderList only contained 100 items, although based on the docs inside this link @ https://pnp.github.io/pnpcore/using-the-sdk/basics-getdata-paging.html#full-load-of-items that LoadAsync will get all items from SharePoint through implicit paging requests.

image

any advice? how i can get all items in one call?

0

There are 0 best solutions below