There are
multiple ways of hiding the SiteActions in the Ribbon:
1. Hiding in the master page
This is probably the simplest version.
Open the master page in Sharepoint designer or
Visual Studio and search for <Sharepoint:SiteActions> control. Enclose
this content inside a SPSecurityTrimmedControl. See code below:
<SharePoint:SPSecurityTrimmedControl
ID="SPSecurityTrimmedControl1" runat="server"
PermissionsString="ManageSubwebs">
<<SharePoint:SiteActions control>>
</SharePoint:SPSecurityTrimmedControl>
The SPSecurityTrimmedControl checks for permission of every
user and only if the user has got required permissions, it will show the
content within this control. In the above code, only if the user has got
ManageSubwebs permission, he/she will be able to see the SiteActions.
If you want to hide/show SPRibbon based on permissions,
enclose the SPRibbon control within the SPSecurityTrimmedControl.
Refer this post for the script.
- Create an Empty Sharepoint Project
- Create a class that inherits Control and add the below code:
protected override void
OnLoad(EventArgs e)
{
base.OnLoad(e);
HideSiteActions();
}
private
void HideSiteActions()
{
MasterPage masterPage =
Page.Master;
if (masterPage == null)
return;
SiteActions siteActions =
masterPage.FindControl("SiteActionsMenuMain") as SiteActions;
/* … Add the code to check
for users permissions … */
siteActions.Visible = false;
}
- Create an Empty Element file and add a Control tag to the element.xml file
<Control
Id="AdditionalPageHead" Sequence="50"
ControlClass="HideSiteActions.HideSiteActionsClass"
ControlAssembly="$SharePoint.Project.AssemblyFullName$"></Control>
</Elements>
- Set the scope of the feature to Site
- Set the Include Assembly in Package property of the project to false
- Add a Safe control entry in the package
- Open the .package and go to Advanced tab
- Add Assembly
- Deploy the project

No comments:
Post a Comment