phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Read items from sharepoint

Open BeginnerRaffe opened this issue 2 years ago • 1 comments

Hello,

I have read that are some issues to read may items from sharepoint? I have tested with 500 and it seams to work for me. Are there any limitations how many items you can read?

I would like to make a query when I read from sharepoint. I got a date field in my sharepoint list and I would like only to read the items that is newer than a specific date. It that possible? (My sharepoint lits will contain many items ...)

I use the code below:

use Office365\SharePoint\ClientContext; use Office365\Runtime\Auth\ClientCredential; use Office365\SharePoint\ListItem;

$credentials = new ClientCredential("{client-id}", "{client-secret}"); $client = (new ClientContext("https://{your-tenant-prefix}.sharepoint.com"))->withCredentials($credentials);

$web = $client->getWeb(); $list = $web->getLists()->getByTitle("{list-title}"); //init List resource $items = $list->getItems(); //prepare a query to retrieve from the. How do I make q query here? $client->load($items); //save a query to retrieve list items from the server $client->executeQuery(); //submit query to SharePoint server /** @var ListItem $item */ foreach($items as $item) { print "Task: {$item->getProperty('Title')}\r\n"; }

BeginnerRaffe avatar Sep 16 '22 12:09 BeginnerRaffe

Sharepoint has an infamous limit of 5000 items, see https://learn.microsoft.com/en-us/sharepoint/troubleshoot/lists-and-libraries/items-exceeds-list-view-threshold - if you hit it, you will get an exception:

{
  "error": {
    "code": "-2147024860, Microsoft.SharePoint.SPQueryThrottledException",
    "message": {
      "lang": "en-US",
      "value": "The attempted operation is prohibited because it exceeds the list view threshold."
    }
}

For lists it is said this can be circumvented by setting indexes on columns: https://www.codeproject.com/Articles/1076854/Overcoming-the-List-View-Threshold-in-SharePoint-C

I failed to get around that limit when using $folder->getFiles() and had to resort to splitting up files into multiple folders.

cweiske avatar Oct 05 '22 09:10 cweiske