Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read items from sharepoint #292

Open
BeginnerRaffe opened this issue Sep 16, 2022 · 1 comment
Open

Read items from sharepoint #292

BeginnerRaffe opened this issue Sep 16, 2022 · 1 comment
Labels

Comments

@BeginnerRaffe
Copy link

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";
}

@cweiske
Copy link
Contributor

cweiske commented Oct 5, 2022

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.

@vgrem vgrem added the question label Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants