Wednesday, July 11, 2012

Hide ribbon in Sharepoint 2010

Ribbon is a great feature in SharePoint 2010, but some times it need to hide. The ribbon can be hide according to the role and from anonymous users. Here is a way by which you can hide the ribbon in Sharepoint 2010. This can be possible through Sharepoint:SPSecurityTrimmedControl control and some modifications in the master page and by using jQuery.You have to only follow the following Seven steps and you will be able to hide the ribbon in Sharepoint 2010.

Step-1:
First of all before modifying anything don’t forget to take a backup of your master page. So before starting for safety purpose cop and paste the masterpage in any other location in notepad

Step-2:
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.

Step-3:
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"/>

Step-4:
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">

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

Step-7:
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">
$(document).ready(function()
{
$('#s4-ribbonrow').show();
});
</script>
</SharePoint:SPSecurityTrimmedControl>

No comments:

Post a Comment