Pages

Thursday, April 7, 2011

How to programmatically lock SharePoint Site Collection while Exporting and other maintenance work

 

[Note : This post is part of  my main blog “Moving Large MOSS 2007 Sites” and “SharePoint 2010 Migration”]

In order to ensure your export remains consistent through the process of Export and then till the completion of Import, consider Read Locking your Exporting Site Collection.  

Lets see how these  UI settings for the locks map to the code options:

SPSite.WriteLocked

image_thumb1

SPSite.ReadOnly

image_thumb2

SPSite.ReadLocked

image_thumb3

Below I am sharing my code base for implementing the ReadOnly locks. Few things to note:

  • When you are assigning any lock, it is important that you first assign the LockHint before setting the Lock as the site collection becomes the respective lock mode.
  • When you are removing any lock, it is important that you first setting the given Lock false. as the site collection becomes released from the respective lock mode. Then clear off the lock hint.

Your Call order

1. LockSiteCollection(SiteCollection);
2. Perform Your Export/Import here
3. UnLockSiteCollection(SiteCollection);

Common Methods you can use:

 

       private void LockSiteCollection(SPSite Site)
{
//Try lock the Portal Site Collection
try
{
Site.LockIssue = “Your Lock reason”;
}
//handle prior left out read only locks due to errors.
catch (UnauthorizedAccessException)
{
Site.ReadOnly = false;
Site.LockIssue = “Your Lock reason”;
}
Site.ReadOnly = true;

}


private void UnLockSiteCollection(SPSite Site)
{

Site.ReadOnly = false;
Site.ReadLocked = false;
Site.WriteLocked = false;
Site.LockIssue = "";
}




Technorati Tags:

No comments: