Expand Minimize

Do not set SPSite.ReadLocked property

Property SPSite.ReadLocked is reserved for internal and is not intended to be used directly from your code. Use the IsReadLocked property instead.

CheckId SPC010213
TypeName DoNotCallSPSiteReadLocked
Severity CriticalWarning
Type Assembly

Use SPSite.IsReadLocked instead (for SP2013) or use the SPSiteAdministration.ReadLocked property of the SPSiteAdministration class (for SP2010) instead .
Bad Practice

using (SPSite site = new SPSite("url"))
{
  // setting a site to "No access" option
  site.LockIssue = "The site was disabled";
  site.ReadLocked = true; // ReadLocked is reserved for internal use
}

Good Practice (SP2010)
using(SPSiteAdministration siteAdministration = new SPSiteAdministration("siteCollectionUrl"))
{
  siteAdministration.LockIssue= "The site was disabled";
  siteAdministration.ReadLocked = true;
}

Good Practice (SP2013)
using (SPSite site = new SPSite("url"))
{
  // setting a site to "No access" option
  site.LockIssue = "The site was disabled";
  site.IsReadLocked = true;
}

To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.

// Important: Ensure to have #define CODE_ANALYSIS at the beginning of your .cs file
[SuppressMessage("SPCAF.Rules.CorrectnessGroup", "SPC010213:DoNotCallSPSiteReadLocked", Justification = "Provide reason for suppression here")]
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.