I have this code to retrive items from sharepoint list and print their Titles:-
//using AngleSharp.Css.Dom;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PnP.Core.Auth;
using PnP.Core.Model.SharePoint;
using PnP.Core.Model.Teams;
using PnP.Core.QueryModel;
using PnP.Core.Services;
using PnP.Core.Services.Builder.Configuration;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Xml.Linq;
//using System.Security.Cryptography.X509Certificates;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace ConsoleApp4
{
internal class Program
{
static async Task Main(string[] args)
{
var tenantId = "**";
var clientId = "***
var certificatePath = @"c:\CERT\Reporting.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");
var workOrderList = context.Web.Lists.GetByTitle("Work Orders", p => p.Title,
p => p.Fields.QueryProperties(p => p.InternalName,
p => p.FieldTypeKind,
p => p.TypeAsString,
p => p.Title));
//Posting UnPosting Forms
// Build a query that only returns these fields for the Work Orders
string viewXml = @"<View Scope='RecursiveAll'>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='Created' />
<FieldRef Name='FileLeafRef' />
<FieldRef Name='LocationName' />
</ViewFields>
<Query>
<Where>
<Eq>
<FieldRef Name='LocationName' />
<Value Type='Text'>Location Main</Value>
</Eq>
</Where>
</Query>
<RowLimit Paged='TRUE'>5000</RowLimit>
</View>";
// Load all the needed data using paged requests
bool paging = true;
string nextPage = null;
while (paging)
{
var output = await workOrderList.LoadListDataAsStreamAsync(new RenderListDataOptions()
{
ViewXml = viewXml,
RenderOptions = RenderListDataOptionsFlags.ListData,
Paging = nextPage ?? null,
}).ConfigureAwait(false);
if (output.ContainsKey("NextHref"))
{
nextPage = output["NextHref"].ToString().Substring(1);
}
else
{
paging = false;
}
}
foreach (var item in workOrderList.Items)
{
Console.WriteLine(item["Title"]);
}
}
}
}
now this is simply printing all the items, and not just the ones requested by the CAML query. now if i add AsRequested() to foreach (var item in workOrderList.Items.AsRequested()), everything will work fine.. so what is going on?
Thanks