I faced the same issue accessing the folders from Sharepoint online. One of my subfolder under Sites rootfolder had 6000+ subfolders, resulting to threshold limit error. So instead, I user alternative way to access only specific folder that I need using GetFolderByServerRelativeUrl function. Steps were...
- Get Online Context
- Get List of items. It will also provide the root folder.
- Using GetFolderByServerRelativeUrl, get only specific folder within this root folder. Below code may help further.
private Folder GetSubFolder(Web web, Folder rootFolder, string subFolderName)
{
Folder subFolder = null;
try
{
//If folder exists, get the folder form Sharepoint Cloud
subFolder = web.GetFolderByServerRelativeUrl(rootFolder.ServerRelativeUrl + "/" +subFolderName);
web.Context.Load(subFolder);
web.Context.ExecuteQuery();
}
catch (ServerException ex)
{
subFolder = null;
}
return subFolder;
}
}