Version 2.4.1
List of changes
-
SharePoint
(for version16.0.20106.12008
) andOutlookServices
models have been updated -
built-in support to retrieve large collections (or paged data) via lazy loading approach
-
support for upload "large" file (chunked upload)
Working with SharePoint large lists and libraries (which contains more than 5000
items)
Due to built-in support, nothing has changed in terms how list items are retrieved to preserve API simplicity, no matter how many items list contains (unless $top
query option is provided to restrict the amount of items to load)
Behind the scene, lazy loading approach is utilized to retrieve paged data, which offers optimal performance since the data is getting load only when requested.
$list = $ctx->getWeb()->getLists()->getByTitle("--Large List Title--");
$items = $list->getItems();
$ctx->load($items);
$ctx->executeQuery();
print $items->getCount() . PHP_EOL; //prints the actual amount of items in list/library
//iterate across all list items
foreach ($items as $index => $item){
print($index . ":" . $item->getProperty('Title') . PHP_EOL);
}
Upload large files
Note: Use this solution if you want to upload files that are larger than 2 MB to SharePoint.
$ctx = ClientContext::connectWithClientCredentials($Url, $ClientId, $ClientSecret);
$localPath = "../data/big_buck_bunny.mp4";
$targetLibraryTitle = "Documents";
$targetList = $ctx->getWeb()->getLists()->getByTitle($targetLibraryTitle);
$session = $targetList->getRootFolder()->getFiles()->createUploadSession($localPath, "big_buck_bunny.mp4",
function ($uploadedBytes) {
echo "Progress: $uploadedBytes bytes uploaded .." . PHP_EOL;
});
$ctx->executeQuery();
$targetFileName = $session->getFile()->getName();
echo "File $targetFileName has been uploaded.";