Friday, February 17, 2012

hide ribbon in sharepoint 2010

Ribbon is a great feature in SharePoint 2010, but some times it need to hide the ribbon from anonymous users. Here is a way by which you can hide the ribbon from anonymous users. This can be possible through Sharepoint:SPSecurityTrimmedControl control and some modifications in the master page and by using jQuery. If you want to read about Sharepoint:SPSecurityTrimmedControl, then visit this article. Also read some jQuery articles here.

First of all before modifying anything take a backup of your master page.

Put the jquery-1.7.1.min.js file inside the layouts folder. Here I have created a folder name as Scripts and put my .js file inside the layouts directory.


Write below code in the master page, to refer to the .js file.
<SharePoint:ScriptLink language="javascript" name="/_layouts/Scripts/jquery-1.7.1.min.js" runat="server"/>

Now its time for modification in the master page.

Search for <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle"> and replace this with below line code (style="display:none")

<div id="s4-ribbonrow" style="display:none" class="s4-pr s4-ribbonrowhidetitle">

Step-5: Now search for this line <div id="s4-ribboncont"> , It usually appears after the above line.
After <div id="s4-ribboncont"> line write <Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageWeb">

Now search for the end ribbon tag that is  </SharePoint:SPRibbon>
And after this line write </SharePoint:SPSecurityTrimmedControl>

Now find this line <div id="notificationArea" class="s4-noti">
And above this line Write the below code:
 <SharePoint:SPSecurityTrimmedControl ID="st1" runat="server" PermissionsString="ManageWeb">
<script type="text/javascript">

This finishes our work. Now publish the page and enjoy.