【问题标题】:How can I restrict what web parts show up in the Add Web Parts window?如何限制在“添加 Web 部件”窗口中显示的 Web 部件?
【发布时间】:2010-11-14 11:45:21
【问题描述】:

我想向一些用户公开 Web 部件,但不是所有用户。如何在“添加 Web 部件”弹出窗口中显示或隐藏 Web 部件?我想通过代码来做到这一点,我希望使用 SharePoint 角色来实现这一点。

【问题讨论】:

  • 不是重复的。

标签: sharepoint web-parts security-roles


【解决方案1】:

我知道您可以管理在 Web 部件库的“添加 Web 部件”窗口中显示哪些 Web 部件。

虽然我没有这样做...因为它只是另一个 SharePoint 列表,您应该能够以编程方式将角色分配给组/用户?

More Info...

更新 - 因为你想看一些代码。没什么特别的,只是快速破解。您肯定会想要进行标准错误检查等。HTH :-)

using (SPSite site = new SPSite("YOUR SP URL"))
{
  using (SPWeb web = site.OpenWeb())
  {
    SPList list = web.Lists["Web Part Gallery"];

    // Your code for choosing which web part(s) to modify perms on
    // will undoubtedly be more complex than this...
    SPListItem listItem = list.GetItemById(19);

    SPPrincipal groupToAdd = web.SiteGroups["YOUR GROUP NAME"] as SPPrincipal;

    SPRoleAssignment newRoleAssignment = new SPRoleAssignment(groupToAdd);
    SPRoleDefinition newRoleDefinition = web.RoleDefinitions["Read"];
    newRoleAssignment.RoleDefinitionBindings.Add(newRoleDefinition);

    listItem.RoleAssignments.Add(newRoleAssignment);
  }
}

【讨论】:

  • 这令人鼓舞,我知道现在可以做到。但我需要用代码来做。
【解决方案2】:

您可以使用 SharePoint 组来做到这一点。

转到 Web 部件库,在您希望确定范围的 Web 部件上单击“编辑”,然后单击“管理权限”。您可以在此处指定哪些用户或组可以使用 Web 部件。

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2011-06-24
    • 1970-01-01
    • 2011-04-16
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多