I have some SP .NET Object library code that will allow me to query for the contents of a specific folder in a document library. It worked fine in a UAT environment where there were only a few dozen folders, but when I moved it to Production where there were 14K folders, it won't return the folders anymore.
I assume that I need a way to get directly to the folder, instead of retrieving the list of folders and then getting the one I need, but I don't know how to do it? I think i could do it with a CAML query, but I can't find a way to get directly to the folder and get the list of files?
Assumumptions:
Site Name = https://xyz.sharepoint.com/sites/CRMDocs/
Library Friendly Name = Case
Library Path = incident
Sample Folder = 0312380e
Full Path = https://xyz.sharepoint.com/sites/CRMDocs/incident/0312380e
Web web = clientContext.Web;
ListCollection lists = web.Lists;
var docLib = web.Lists.GetByTitle(entityFriendlyName);
clientContext.Load(docLib, d => d.Title, d => d.RootFolder.Name);
clientContext.ExecuteQuery();
String folderUrl = String.Format("/{0}/{1}", docLib.RootFolder.Name, folderName);
var folders = docLib.RootFolder.Folders;
clientContext.Load(folders, fldrs => fldrs.Include(fldr => fldr.ServerRelativeUrl));
clientContext.ExecuteQuery();
// When there are more than 5K folders, folders collection is NULL
var folder = folders.FirstOrDefault(f => f.ServerRelativeUrl.ToLower().EndsWith(folderUrl.ToLower()));
if (folder != null)
{
var files = folder.Files;
clientContext.Load(files);
clientContext.ExecuteQuery();
// Process Files
}
docLib.RootFolder.Folders