如何限制“添加 Web 部件”窗口中显示的 Web 部件?

发布于 2024-07-29 04:26:41 字数 107 浏览 4 评论 0原文

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

I'd like to expose a web part to some users, but not all of them. How can I show or hide a web part in the Add Web Parts pop up window? I'd like to do this through code, and I'm hoping to use SharePoint Roles to make this happen.

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

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

发布评论

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

评论(2

鹿港巷口少年归 2024-08-05 04:26:41

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

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

更多信息...

更新 - 因为您想查看一些代码。 没什么特别的,只是一个快速破解。 您肯定会想要进行标准错误检查等。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);
  }
}

I know you can manage which web parts show up in the Add Web Parts window in the Web Part Gallery.

While I haven't done it... since it's just another SharePoint List, you should be able to programmatically assign roles to Groups/Users?

More Info...

Update - Since you want to see some code. Nothing special, just a quick hack. You'll definitely want to do your standard error checking, etc. 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);
  }
}
枕头说它不想醒 2024-08-05 04:26:41

您可以使用 SharePoint 组来执行此操作。

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

You can do this with SharePoint Groups.

Go to the Web Part Gallery, click "Edit" on the web part you wish to scope, then click Manage Permissions. Here you can specify which users or groups can use the web part.

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