是否可以以编程方式向网站授予组(在 SharePoint 中)权限?

发布于 2024-10-07 18:39:03 字数 431 浏览 0 评论 0原文

我正在使用 SharePoint 对象模型以编程方式创建新网站(使用自定义 Web 部件)。它工作正常,但我想知道是否也可以向团体授予权限?

当我创建站点时,我已将其设置为不继承权限

newWeb = SPContext.GetContext(HttpContext.Current).Web.Webs.Add(siteUrl, siteName, siteDescription, (uint)1033, siteTemplate, true, false);

在 GUI 中,我可以转到站点操作(在新创建的站点上)->授予许可 ->在父站点中搜索组,然后授予该组权限。因此,在父站点中 myGroup 可以具有完全访问权限,但在此站点中我可以将其设置为贡献或其他权限。是否可以在创建网站时或之后(以编程方式)执行此操作?

提前致谢。

I am using the SharePoint Object Model to create new sites programmatically (with a custom web part). It works fine but I am wondering if it is possible to grant permission for groups as well?

When I create the site I have set it to not inherit permission

newWeb = SPContext.GetContext(HttpContext.Current).Web.Webs.Add(siteUrl, siteName, siteDescription, (uint)1033, siteTemplate, true, false);

In the GUI I can then go to Site Actions (on the newly created site) -> Grant Permission -> search for groups in the parent site and then grant permission for this group. So, in the parent site myGroup can have Full Access permissions but in this site I can set it to Contribution or whatever. Is it possible to do this when I create the site or just after (programmatically)?

Thanks in advance.

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

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

发布评论

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

评论(1

陈独秀 2024-10-14 18:39:03

您必须为您的组分配角色定义。

下面是我编写的代码片段,用于将预定义的共享点角色定义分配给一组。

public bool AssignExistingGroupToWeb(SPWeb siteWeb, string GroupName, SPRoleDefinition roleDefinition)
{
//retrieve a group
SPGroup siteGroup = siteWeb.SiteGroups.FindGroupByName(GroupName);

//create a role assignment for the group using the specified SPRoleDefinition
//examples of roles as "Full Control", "Design", etc...
SPRoleAssignment roleAssignment = new SPRoleAssignment(siteGroup);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
siteWeb.RoleAssignments.Add(roleAssignment);
siteWeb.Update();
}

您可以通过访问 RoleDefinitions 集合来检索 SPRoleDefinition,如下所示...

siteWeb.RoleDefinitions["Contribute"]

You must assign a role definition to your group.

Here's a code snippet I wrote to assign a group one of the predefined sharepoint role definitions.

public bool AssignExistingGroupToWeb(SPWeb siteWeb, string GroupName, SPRoleDefinition roleDefinition)
{
//retrieve a group
SPGroup siteGroup = siteWeb.SiteGroups.FindGroupByName(GroupName);

//create a role assignment for the group using the specified SPRoleDefinition
//examples of roles as "Full Control", "Design", etc...
SPRoleAssignment roleAssignment = new SPRoleAssignment(siteGroup);
roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
siteWeb.RoleAssignments.Add(roleAssignment);
siteWeb.Update();
}

You can retrieve a SPRoleDefinition by accessing the RoleDefinitions collection, like so...

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