隐藏 SharePoint 列表/文档库中的新建/操作/上传/设置菜单

发布于 2024-07-27 21:35:18 字数 453 浏览 2 评论 0 原文

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

我知道的一种可能的方法是注册一个 ,并将 ControlClass 元素设置为从 WebControl 继承的控件。 在 WebControl 中,我可以重写 OnPreRender,然后执行此操作:

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

    // etc
}

这非常 hacky,我只是想知道是否有更好的方法来做到这一点?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

手心的温暖 2024-08-03 21:35:18

您可以使用属于 SharePoint 2007 功能 Codeplex 项目的工具栏管理器 Web 部件来实现此目的。
http://features.codeplex.com/

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

如果某些用户需要菜单项,请授予他们添加个人视图的权限。 当他们创建个人视图时,默认情况下不会安装 Web 部件。 此外,您还需要禁止不应访问菜单项的用户进行个人视图。

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.

残疾 2024-08-03 21:35:18

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

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]);
               }
          }                  
    }
}
懵少女 2024-08-03 21:35:18

我刚刚写了一篇博客文章 此处为您隐藏了按钮。 希望能帮助到你。

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

生活了然无味 2024-08-03 21:35:18

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文