隐藏新建/操作/上传/设置在SharePoint列表/文档库菜单(Hide New / Action

2019-10-17 02:31发布

如何隐藏新建/操作/上传/设置在SharePoint列表或文档库中的菜单? 请注意,我需要能够隐藏这些菜单特定列表定义(模板),而不是刚才的所有列表或文档库。

我知道一个可能的方法就是注册一个,和ControlClass元素设置为从Control继承的控制。 在WebControl的,我可以重写的OnPreRender,然后做到这一点:

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

    // etc
}

这是相当哈克,我只是想知道是否有这样做的更好的办法?

Answer 1:

您可以使用此工具栏管理器Web部件是SharePoint 2007的一部分功能的CodePlex项目acheive。 http://features.codeplex.com/

您需要将Web部件添加到每个视图的网页,但它允许您隐藏菜单项无需编码。

如果某些用户需要的菜单项,给他们批准,可以增加个人的看法。 当他们创建一个个人的观点,Web部件将不被默认安装的。 同时,你需要禁止个人观点用户不应该访问的菜单项。



Answer 2:

JavaScript的可能是你最好的选择。 只需修改并请参见该代码在你的母版页:

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]);
               }
          }                  
    }
}


Answer 3:

我只写了一个博客条目在这里的这里面隐藏的按钮为您服务。 希望能帮助到你。



Answer 4:

如果您没有在列表中的任何非隐藏的内容类型,在“新建”按钮会自动消失。



文章来源: Hide New / Actions / Upload / Settings menus in SharePoint Lists / document libraries