Hiding Menus in SharePoint

on Tuesday, November 3, 2009

Alternatives

  1. If you want to hide a menu on perticular page then use CEWP(Content Editor WebPart) and put javascript in Source Editor to hide the menu. The id of the menu can be found using ViewSource from the browser. For example to hide siteactions menu from a perticular page use below javascript. Note that to execute any javascript after onload you haveto use _spBodyOnLoadFunctionNames function.


    <script language="JavaScript">
    _spBodyOnLoadFunctionNames.push("HideNewIcons");
    function HideNewIcons()
    {
    var doc = document.getElementById('siteactiontd');
    doc.style.visibility="hidden";
    }
    </script>

  2. Modify default.master page and put it inside that file.

  3. Use a Feature.

    If you want to control the hiding of the menus by using a Feature so you can turn them on and off at will, and at the farm, application, site collection or site level the you have a little more work to do, but not too much.
    I will return here later and add a full step by step, but here's the code you will need:

    A SharePoint Delegate control:

    Add this to the bottom of your Master Page just before the </body> tag (The ControlId is up to you, but needs to match the Id used in the elements file):
    <SharePoint:DelegateControl runat="server" ControlId="MiscControls" AllowMultipleControls="true"/>


    A .Net User Control: HideMenus.ascx
    <%@ Control Language="C#" ClassName="HideMenus" %>

    <script language="JavaScript">
    var doc = document.getElementsByTagName('ie:menuitem');
    for (var i = 0; i < doc.length; i++){
    itm = doc(i)
    if (itm.id.match('MultipleUpload')!=null itm.id.match('OpenInExplorer')!=null)
    {
    itm.hidden=true;
    }
    }
    </script>


    A feature file: Feature.xml
    <Feature
    Id="531F15CD-A646-45e5-AB61-4F8DF89C29D9"
    Title="Hide Menus"
    Description="Sample feature to hide selected menus (MAX Technical Training demo)"
    Scope="Web"
    Hidden="FALSE"
    xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests>
    <ElementManifest Location="elements.xml" />
    </ElementManifests>
    </Feature>


    An elements file: Elements.xml


    <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control ControlSrc="~/_controltemplates/HideMenus.ascx" Sequence="100"
    Id="MiscControls">
    </Control>
    </Elements>

0 comments: