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:
- Central Administration by Administrator
- PowerShell by Administrator
- 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.
In the page that appears, enter the site collection details.
Open the site and ensure you can add contents.
Option 1: Making Read-Only through Central Administration
Go to Central Administration and select "Application Management" > "Configure quotas and locks".
In the page that appears, choose the site collection and select the option Read-only.
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.
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".
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.
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.
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.
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.
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.
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.