sudhanshu rai

sudhanshu rai

  • NA
  • 26
  • 926

Not Get ListItems using SharePoint AppOnly Authentication

Apr 13 2020 12:30 AM
Hi Everyone,
 
We are using app-id and secret for fetching List items and using OfficeDevPnP Nuget for it. We are the owner of SharePoint app and already give FullControl to collection. We are able to get the collection names, Field names of particular List but not ListItems. Sample code snipped for reference.
using OfficeDevPnP.Core;
using Microsoft.SharePoint.Client;
using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, appId, appSecret))
{
CamlQuery caml = new CamlQuery();
caml.ViewXml = "<View><Query><OrderBy><FieldRef Name='Created' Ascending='false' /></OrderBy></Query><RowLimit>5</RowLimit></View>";
var requestItems = clientContext.Web.Lists.GetByTitle(listName).GetItems(caml);
clientContext.Load(requestItems);
clientContext.ExecuteQuery();
foreach (var item in requestItems) // requestItems count is 0, even its contain values.
{
Console.WriteLine(item["Title"]);
}
}
 

Answers (5)