pnp / pnpcore

The PnP Core SDK is a modern .NET SDK designed to work for Microsoft 365. It provides a unified object model for working with SharePoint Online and Teams which is agnostic to the underlying API's being called
https://aka.ms/pnp/coresdk/docs
MIT License
288 stars 188 forks source link

Support for breaking role inheritance on Folders #1429

Closed kgr7 closed 3 months ago

kgr7 commented 3 months ago

Category

Describe the feature

As a SharePoint admin I can break permission inheritance and define a specific audience and permissions for any given folder in a document library. As far as I can see, this is not possible to do currently with PnP Core. It can be done for Lists but seemingly not folders.

I was wondering if there is some technical reason this isn't supported or if it has simply not been added yet. It would really help my project as we are trying to automate provisioning of sites, documents and folders.

Describe the solution you'd like

Ideally, I think I would like Folders to behave similarly to Lists which would offer more granular permission/audience control and an alternative to creating a whole other new document library.

jansenbe commented 3 months ago

@kgr7 : a Folder is nothing more than an List Item and we do support breaking permission inheritance for list items (see https://pnp.github.io/pnpcore/using-the-sdk/security-intro.html#breaking-permission-inheritance). Something like below snippet should work:

var source = await context.Web.GetFolderByServerRelativeUrlAsync(folder.ServerRelativeUrl, x => x.ItemCount, x => x.Folders, x => x.Files, x => x.ListItemAllFields);

await source.ListItemAllFields.BreakRoleInheritanceAsync(false, true);
jansenbe commented 3 months ago

@kgr7 : did the above help?

kgr7 commented 3 months ago

@kgr7 : did the above help?

Sorry I forgot to reply! Yes it did help thank you this is what I was looking for 🙂