Hide New / Actions / Upload / Settings menus in Sh

2019-08-08 02:25发布

问题:

How can I hide the New / Actions / Upload / Settings menus within a list or document library in SharePoint? Note that I need to be able to hide these menus for a particular list definition (template) and not just all lists or document libraries.

One possible way that I know of is to register a , and set the ControlClass element to a control that inherits from WebControl. In the WebControl, I can override OnPreRender, which then does this:

foreach (Control control in this.Parent.Controls)
{
    if (control.ToString() == "Microsoft.SharePoint.WebControls.NewMenu")
    {
        control.Visible = false;
    }

    // etc
}

This is pretty hacky, and I was just wondering if there is a better way of doing it?

回答1:

You can acheive this using the Toolbar Manager web part that is part of the SharePoint 2007 Features Codeplex project. http://features.codeplex.com/

You need to add the web part to the each view web page, but it allows you to hide menu items without coding.

If some users need the menu item, give them permission to add personal views. When they create a personal view, the web part will not be installed by default. As well, you will need to disallow personal views for users that should not be to access the menu items.



回答2:

JavaScript is probably your best option. Just modify and refer to this code in your Master Page:

hideListViewToolbarItems("list settings","document library settings","create column","open with windows explorer");

function hideListViewToolbarItems()
{      
    var menuItem;         
    var menuItemName;
    var menuItemIndex=-1;
    var menuItemNames=new Array("edit in datasheet","open with windows explorer",
    "connect to outlook",'export to spreadsheet','view rss feed','alert me'
    ,"create column","settings:create view","list settings",
    "document library settings","explorer view","all documents",
    "all items","modify this view","view:create view","new document",
    "new item","new folder","upload document","upload multiple documents");
    var menuItems = new Array("EditInGridButton","OpenInExplorer","OfflineButton",
    "ExportToSpreadsheet","ViewRSS","SubscribeButton","AddColumn",
    "AddView","ListSettings","ListSettings","View1","DefaultView",
    "DefaultView","ModifyView","CreateView","New0","New0",
    "NewFolder","Upload","MultipleUpload");              
    var allMenuItems = document.getElementsByTagName('ie:menuitem');
    for(var i = 0; i < hideListViewToolbarItems.arguments.length; i++ ) 
    {                                                                           
          menuItemName= hideListViewToolbarItems.arguments[i].toLowerCase();
          for (j=0; j < menuItemNames.length; j++)
          {
               if(menuItemNames[j]==menuItemName)
               {                                     
                     menuItemIndex = j;
                     break;
               }
          }           
          menuItem=menuItems[menuItemIndex];
          for (var l = 0; l < allMenuItems.length; l++)
          {                  
               if(menuItemName.indexOf(":")!=-1)
               {
                         menuItemName = menuItemName.split(":")[1];
               }
               if (allMenuItems[l].id.indexOf(menuItem)!=-1 
                && allMenuItems[l].text.toLowerCase() == menuItemName )
               {                  
                     // For FireFox Compatibility
                     var parentNodeOfMenuItem = allMenuItems[l].parentNode;
                     parentNodeOfMenuItem.removeChild(allMenuItems[l]);
               }
          }                  
    }
}


回答3:

I just wrote a blog entry here on this which hides the button for you. Hope it helps.



回答4:

If you don't have any non-hidden content types in your list, the "new" button will automatically disappear.