Friday, 1 November 2013

SharePoint 2010: Configure access request settings using Powershell


# Get All Web Application
$webApp=Get-SPWebApplication
   # Get All site collections
    foreach ($SPsite in $webApp.Sites)
    {
       # get the collection of webs
       foreach($SPweb in $SPsite.AllWebs)
        {
              # if a site inherits permissions, then the Access request mail setting also will be inherited
             if (!$SPweb.HasUniquePerm)
               {
                  Write-Host $SPweb.Name "Inheriting from Parent site"
               }
             elseif($SPweb.RequestAccessEnabled)
           {
        #Write-Host $SPweb.Name "Not Iheriting from Parent Site"
              $SPweb.RequestAccessEmail ="ram001@sample.com"
          $SPweb.Update()
           }
        }
    }

****** HAPPY CODING ********

SharePoint 2010: Setting Value for Web Part’s Custom Properties


To set the Custom Properties of web part programmatically, Following approach is useful. 


if (string.Equals(webPart.GetType().ToString(), “MyWebpartram001”)) 


  PropertyInfo[] pinProperties = webPart.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); 
foreach (PropertyInfo pinProperty in pinProperties) 

  if (pinProperty.Name == "Toolbar") 
 { 
   pinProperty.SetValue(webPart, false, null); 
   break; 
  } 
 } 
} 

****** HAPPY CODING ********