Wednesday, July 25, 2012

Site Collection Locks in SharePoint

Locks can be Set/Reset in 4 ways:
  1. Using Web User Interface - Through Central Administration
  2. Using STSADM 
  3. Using PowerShell
  4. Using Object Model
    1. By .Net code
    2. By PowerShell
Using Web User Interface: 
Where to Look? Go to Central Administration > Application Management > Configure Quotas and Locks >Select Site collection >Select lock status option

STSADM:

To set Lock:
stsadm -o setsitelock -url <Site-collection-url> -lock <Lock-Type>

To Check current locks applied:
stsadm -o getsitelock -url <Site-collection-url>

Where <Lock-Type> can take one of the following value: 
  • none  - Removes all the locks
  • noadditions  - Prevents from Addition
  • readonly - Can't add/Update/Delete content
  • noaccess - You can't view the site at all
PowerShell:
Set-SPSite -Identity <Site-collection-url> -LockState <Lock-State>

Where: <Lock-State> can be:
  •     ReadOnly
  •     Unlock
  •     NoAdditions
  •     NoAccess 
Ex. 
$site = Get-SPSite -Identity <site url>
$site.readonly = $false 

Object Model:
You can Programmatically set the Lock status using SPSite object's Properties:
  •     SPSite.ReadLocked
  •     SPSite.WriteLocked
  •     SPSite.ReadOnly
Code Sample :

    using (SPSite site = new SPSite("http://spserver2:3030"))
                {
                    using (SPWeb sharePointWeb = site.RootWeb)
                    {
                        site.AllowUnsafeUpdates = true;
                        sharePointWeb.AllowUnsafeUpdates = true;

                     
                        site.ReadOnly = true;
                        site.LockIssue = "Tesing Lock";

                        site.AllowUnsafeUpdates = false;
                        sharePointWeb.AllowUnsafeUpdates = false;
                     }
                 }

No comments:

Post a Comment