Let’s say I have a Document Library “Documents” with structured folders like this:
- Folder1(ID1) - SubfolderA(ID3) file-1-in-SubFolderA(ID4).txt file-2-in-SubFolderA(ID5)checked-out.txt - SubfolderB(ID6) file-1-in-SubFolderB(ID7)checked-out.txt file-1-in-Folder1(ID8)checked-out.txt - Folder2(ID2) file-1-in-Folder2(ID9).txt file-2-in-Folder2(ID10)checked-out.txt
I need to get IDs of all checked out files beneath Folder1. In case of this example I would have IDs (5;7;8)
I can do this like this:
/_api/web/Lists/getbytitle('Documents')/items?$top=1000&$select=FieldValuesAsText/ID&$expand=FieldValuesAsText&$filter=((CheckoutUser ge '1') and (FSObjType eq '0') and (startswith(FileRef, ' MySite/Documents/Folder1/')))
But for large libraries (30 000 items) it is getting very slow as it probably goes through all items in all folders.
So, my second approach was using getfolderbyserverrelativeurl:
/_api/web/getfolderbyserverrelativeurl('/MySite/Documents/Folder1')/files?$expand=ListItemAllFields&$top=100&$filter=((CheckOutType eq 0) or (CheckOutType eq 1))&$select=ListItemAllFields/ID
But this returns me only files that are in Folder1 and will not return files that are located in subfolders.
My third approach was something like this:
/_api/web/getfolderbyserverrelativeurl('/MySite/Documents/Folder1')?$expand=Files,Files/ListItemAllFields,Folders/Files,Folders/Files/ListItemAllFields,Folders/Folders/Files,Folders/Folders/Files/ListItemAllFields&$select=Files/ListItemAllFields/ID,Files/CheckOutType,Folders/Files/ListItemAllFields/ID,Folders/Files/CheckOutType,Folders/Files/Name,Folders/Folders/Files/ListItemAllFields/ID,Folders/Folders/Files/CheckOutType,Folders/Folders/Files/Name&$top=100&$filter=((CheckOutType eq 0) or (CheckOutType eq 1))
That one returns me files few levels deep in subfolders as well, works quite fast, but I can’t use filters on it to return only files that are checked out.
Anyone with great ideas how to achieve described results without overloading the server and not taking forever to complete with large libraries? If that matters, I am on SP 2013.