How to Make a Site Collection ReadOnly in SharePoint 2010

SharePoint 2010 - How to make a Site Collection Read-Only?

In this article, we can explore how to make a Site Collection read-only.

Why make a Site Collection Read-Only?

During phases like development, requirements cut off and release the Administrator might require the Site-Collection to be read-only to prevent future add/edit/delete of contents.

What are the ways to make Site Collection Read-Only?

We can employ the following ways:

  1. Central Administration by Administrator
  2. PowerShell by Administrator
  3. Server Object Model by Developer

Depending on the requirements, we can use the above 3 ways. Let us explore all the 3 ways.

Create Site Collection

For demonstration purposes, I prefer you create a new site collection from Central Administration.

SharePoint2010-1.jpg

In the page that appears, enter the site collection details.

SharePoint2010-2.jpg

Open the site and ensure you can add contents.

SharePoint2010-3.jpg

Option 1: Making Read-Only through Central Administration

Go to Central Administration and select "Application Management" > "Configure quotas and locks".

SharePoint2010-4.jpg

In the page that appears, choose the site collection and select the option Read-only.

SharePoint2010-5.jpg

Enter the lock information and click the "Ok" button to continue.

Testing Read-only

Now we are ready to test the read-only functionality.  Open the site collection main site and try to add a document.  You should see the following error message.

SharePoint2010-6.jpg

This ensures you cannot add/edit/delete contents. The site is read-only.

Unlocking

Please return to the Central Administration Lock Page and choose "Not locked".

SharePoint2010-7.jpg

Now the site collection will be back to writeable mode.

Option 2: Making Read-Only through PowerShell

Now let us try the PowerShell option.  Open the SharePoint enabled PowerShell from the Start menu.

SharePoint2010-8.jpg

Enter the following command for locking the SharePoint site collection by URL:

Set-SPSite -Identity "http://hp/sites/sc2" -LockState "ReadOnly"

Testing Read-only

Open the site collection main site and try to add a document.  You should see the same error message.

SharePoint2010-9.jpg

This confirms the site collection is now read-only.

Unlocking

Now to return the site to writeable, use the following code in a PowerShell window.

Set-SPSite -Identity "http://hp/sites/sc2" -LockState "Unlock"

Now the site collection will be restored to writeable mode.

Option 3: Making Read-Only through Code

Now we can try the Server Object Model way of making a site collection read-only.

Create a new console application, add a reference to the Microsoft.SharePoint assembly and execute the following code.

SPSite site = new SPSite("http://hp/sites/sc2");

site.ReadOnly = true;

Testing Read-only

Open the site collection main site and try to add a document.  You should see the following error message.

SharePoint2010-10.jpg

This confirms that the site collection is now read-only.

Unlocking

Now to return the site back to writeable, use the following code.

SPSite site = new SPSite("http://hp/sites/sc2");

site.ReadOnly = true;

Now the site collection will have been restored to writeable mode.

SharePoint2010-11.jpg

Please note that there are the following 3 lock options:

  • Read-Only where add/edit/delete of contents are prevented
  • Adding content prevented where adding is prevented, but edit/delete is still possible
  • No Access where even reading is prevented.

SharePoint2010-12.jpg

References

http://technet.microsoft.com/en-us/library/ff631148(v=office.14).aspx

Summary

In this article we have explored a real-world scenario of making the site collection read-only, through multiple options possible.