Archive for April, 2015

Setting Site Collection to ReadOnly through CSOM

Tuesday, April 21st, 2015

If working with SharePoint Online we have the ability to set LockState in order to set a site collection to read only. Unfortunately this is currently not available on-premises. Instead we can use Site Policies to apply a read only state to the site collection. In order to do this, create a Site Policy with the setting “Do not close or delete site automatically.” and “The site collection will be read only when it is closed.”. If you want to set read only to several site collections you can create this policy in the content type hub and have the policy published to all site collections. Once the policy exist in the site collection you can run the following CSOM code to set the site as read only:


[code lang=”csharp”]
ProjectPolicy.CloseProject(clientContext, clientContext.Web);

ApplySitePolicy is an extension method in OfficeDevPnP.

readonly">Entries (RSS) and Comments (RSS).