Forum Discussion
Add new Site Policy in SharePoint Online by code
Hi there,
I am looking for a way to create a Site Policy in a SharePoint Online site collection by code (C# or PowerShell). I am wondering that for assigning a Site Policy to a site classes and methods are available in the CSOM, but there is nothing for creating the policies. And when there is anything, it's in a hidden place, where nobody can find it.
I have also tried to create the content type for the Site Policy by code to have a workaround, but the content type needs additional information in its XmlDocument member, but via Rest it is not possible to save this data.
The reason why I need the Site Policy is the site lifecycle, we need to implement. After a specific amount of time the site collection should be set into a read-only mode. The only way I see, is the Site Policy with its "The site collection will be read only when it is closed" setting. If there is any other way (no, removing the permissions is not a solution), then I maybe do not need the Site Policy.
Any hints are welcome. Maybe something for the PnP team (and they do a really good work!).
Thanks
Olaf
- Olaf DidszunCopper Contributor
Ok, not what I really wanted, but an approach to create a site policy automatically, when a site collection is created. I don't know why, but without the modifications on the content type for the site policy, the content type hub won't publish the site policy content type to other site collections.
Maybe there is anyone from the SharePoint product group, who can tell me, whether the approach is a no-go or not.
Thanks,
Olaf