Subscribe: SharePoint SharePoint SharePoint

Wednesday, February 5, 2014

"Sign in as Different User" menu option is missing in SharePoint 2013

In SharePoint 2013 you might have noticed that "Sign in as different User" menu option has been removed. Microsoft has decided to discontinue this option owing to a variety of different reasons. Though to SharePoint Admins and Approvers it might seem to be a big issue.

Since in SharePoint 2010, this menu option did offer a lot of help in checking the permission levels for various groups in SharePoint sites, same thing does not hold true for SharePoint 2013.



The reasons which might have caused Microsoft to remove this option may be summarized as below:

1. There are a lot of caching problems. The cache for one user can contradict with the other one.
2. Page content might show data and content from previous logged in users.

Now there are a number of ways to use this option :

1. In the browser just  append this link to your site url : /_layouts/closeConnection.aspx?loginasanotheruser=true

2. Another permanent solution is to make changes to the welcome.ascx user control which is located at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\welcome.ascx"

Add the following code in it before this tag --> "SharePoint:MenuItemTemplate tag with id ID_RequestAccess":

 <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser"  
 Text="<%$Resources:wss,personalactions_loginasdifferentuser%>"   
 Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>"   
 MenuGroupId="100"  Sequence="100"  UseShortId="true"  />  

After doing this do an IISREST and you should be able to see the required option :




Tuesday, February 4, 2014

Check in and approve all publishing pages using PowerShell in SharePoint

We have a SharePoint 2013 farm setup for our company Intranet. There are huge number of sites in the intranet. Each site is maintained by a separate group. Now the people who maintain those sites are non-technical people.

Since all the sites are publishing sites, so the pages need to be published everytime they are edited. I have repeatedly sent mails to all groups stating that this procedure has to followed everytime they make changes.

But alas! , everyday my mailbox is clogged with requests reporting that "changes are not being reflected to site visitors". Instead of sending separate mails to each of them, i made a powershell script to publish all their pages together.

Note: The image is just for reference. Its not actual screenshot of the below code.

I actually used a timer service to run this script everyday at 5 AM. Finally after few days, i started getting very few requests. So thought of sharing the script:

 $listname = "Pages"   
 $url = "http://myWebApp/sites/mySite"  
    
 function approvePublishContent ($w, $listName) {  
  $list = $w.Lists |? {$_.Title -eq $listName}  
  foreach ($item in $list.Items)   
  {
   //Checking if item is locked
   if(($item -ne $null) -and ($item.LockId -ne $null)) {  
    $item.ReleaseLock($item.LockId)  
   }  
   if( $item.File -ne $null) { $itemFile = $list.GetItemById($item.ID).File }  
   else { $itemFile = $list.GetItemById($item.ID) }  
   
   //Checking in the item
   if( $itemFile.CheckOutStatus -ne "None" ) {   
    $itemFile.CheckIn("Automatic CheckIn. (SysAdmin)")  
    if( $item.File -ne $null) { $itemFile = $list.GetItemById($item.ID).File }  
    else { $itemFile = $list.GetItemById($item.ID) }  
   }  

   //Publishing the item
   if( $list.EnableVersioning -and $list.EnableMinorVersions) {   
    $itemFile.Publish("Automatic Publish. (SysAdmin)")  
    if( $item.File -ne $null) { $itemFile = $list.GetItemById($item.ID).File }  
    else { $itemFile = $list.GetItemById($item.ID) }  
   }  

   //Approving it in case approval is required
   if( $list.EnableModeration ) {   
    $itemFile.Approve("Automatic Approve. (SysAdmin)")   
   }  
  }  
 }  
 $site = Get-SPSite $url  
 foreach ( $web in $site.AllWebs )  
 {  
  approvePublishContent $web $listname  
 }  
 Write-Output "OK"  
   

Monday, February 3, 2014

Updating Web part properties using PowerShell in SharePoint

Web part properties define the structure as well as functionality of a web part. They are quite useful while configuring a web part. We have a huge list of web part properties which have been defined by microsoft. you can have a look over these properties from the link below:

SharePoint Web part properties

Now once i ran into a situation wherein i had to change the "ChromeType" property of a web part in the landing page of all the subsites as well as root site in my site collection. There were a total of 32 subsites. So in order to do this through User Interface would have required a considerable amount of time.
SharePoint 2010

So i created a powershell script to do so and voila! I was able to do so in a single shot.

Each web part page is associated with a "SPWebPartManager" class. This class in particular contains references to all the web parts on the page. So in order to access my web part i have to iterate through the "SPWebPartManager" class.

Here the web part name is "Relevant Articles" and the chrome property has to be set to "TitleAndBorder".
  
 //Get reference to the SPSite object
 $SPsite = Get-SPSite "http://mywebapp/sites/mySite"  
   
 //Iterate through all sub sites and root site  
 foreach($SPWeb in $SPsite.AllWebs){  
   
 //Get reference to the landing page. Since it is a publishing site so default.aspx is the landing page  
 $page = $SPWeb.GetFile("Pages/default.aspx")  
   
 //Checkout the page  
 $page.CheckOut()  
   
 //Get reference to the webpartmanager class  
 $webpartmanager = $SPWeb.GetLimitedWebPartManager("Pages/default.aspx",   
 [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)    
   
   
 //Iterate through webparts in webpartmanager class  
  for($i=0;$i -lt $webpartmanager.WebParts.Count;$i++)  {   
   
 //Check for the name of required web part   
  if($webpartmanager.WebParts[$i].title -eq "Relevant Articles")   
  {    
   
     //Get reference to the web part  
     $wp=$webpartmanager.WebParts[$i];  
       
     //Set the chrome property  
     $wp.ChromeType="TitleAndBorder";  
   
     //Save changes to webpartmanager. This step is necessary. Otherwise changes won't be reflected  
     $webpartmanager.SaveChanges($wp);  
       
     break;   
   
  }   
 }   
   
  //Check in and Publish the page  
  $page.CheckIn("Relevant Articles")  
  $page.Publish("Relevant Articles")  
   
  // Update the SPWeb object  
  $SPWeb.Update();   
    
  //Dispose SPWeb object  
  $SPWeb.Dispose();  
 }