-
I have a "outer" folder, inside of which there are 100.000+ sub folders. I need to go through all of these folders and set their permissions. I can do this one by one, but I can not figure out how to load these folders in a batched way. I think it is because skip/take is not supported on Any suggestions would be appreciated. using var spContext = await pnpContextFactory.CreateAsync("");
var archiveFolderPath = $"{spContext.Uri.PathAndQuery}/Delte dokumenter/Archive";;
var containingFolder = await spContext.Web.GetFolderByServerRelativeUrlAsync(archiveFolderPath);
var roleDefinitions = (await spContext.Web.GetAsync(p => p.RoleDefinitions)).RoleDefinitions;
var role = roleDefinitions.AsRequested().FirstOrDefault(p => p.Id == 123);
var index = 0;
var pageSize = 100;
while (index < 100000)
{
// also tried
//await foreach(var folder in containingFolder.Folders.AsAsyncEnumerable())
// but this also throws throttling error
var folders = await containingFolder.Folders.Skip(index * pageSize).Take(pageSize).QueryProperties(x => x.ListItemAllFields, x => x.Name).ToListAsync();
foreach (var folder in folders)
{
var item = folder.ListItemAllFields;
await item.ResetRoleInheritanceBatchAsync();
await item.BreakRoleInheritanceBatchAsync(copyRoleAssignments: false, clearSubscopes: true);
// In the real case the principalId is different depending on the folder
var principalId= 123;
await item.AddRoleDefinitionBatchAsync(principalId: principalId, roleDefinition: role);
}
await spContext.ExecuteAsync();
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Not a direct answer to your question but just so that you are aware of possible limitations you might (or already have) run into. There are some limitations when you are getting into that large document libraries, see SharePoint Online Limits. As you don't specify the exact structure of your library it's hard to say if that is the case here but these limitations tend to come into play in different ways so it could be what you are seeing here. |
Beta Was this translation helpful? Give feedback.
@archigo : checkout below code, I just enumerated 11K+ folders with it: