c# - 如何将特定 SharePoint 组添加到列表权限

标签 c# sharepoint sharepoint-2010 sharepoint-2007

using (SPSite site = (SPSite)properties.Feature.Parent)
{
   using (SPWeb web = site.OpenWeb())
   {
        if (web != null)
        {
              web.AllowUnsafeUpdates = true;
              SPList list = web.Lists["Alert Status v1.0"];

              //Creates a new role assignment for a group
              SPGroup myGroup = web.SiteGroups["IKM Manager"];
              SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;

              // SPRoleAssignment accepts a SPPrincipal which can be a SPUser or SPGroup
              SPRoleAssignment roleAssignment = new SPRoleAssignment(myGroup);

              //Add the new role assignment to the collection of role assignments for the site.
              roleAssignments.Add(roleAssignment);

              // Stop inheriting permissions
              list.BreakRoleInheritance(true);
              list.RoleAssignments.Add(roleAssignment);
              list.Update();

我在 RoleAssignments.Add(roleAssignment) 上遇到错误,例如“无法添加具有空角色定义绑定(bind)集合的角色分配”。我想停止继承权限并将特定组添加到列表权限。你能帮助我吗?请..

谢谢

最佳答案

这应该有效。

list.BreakRoleInheritance(true);
SPGroup groupAdmin = web.SiteGroups["IKM Manager"];
SPRoleAssignment roleAssignmentAdmin = new SPRoleAssignment((SPPrincipal)groupAdmin);
SPRoleDefinition roleAdmin = web.RoleDefinitions.GetByType(SPRoleType.Administrator);
roleAssignmentAdmin.RoleDefinitionBindings.Add(roleAdmin);
list.RoleAssignments.Add(roleAssignmentAdmin);
list.Update();

关于c# - 如何将特定 SharePoint 组添加到列表权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11761391/

相关文章:

c# - Entity Framework 构造函数错误

javascript - 将共享点列表下拉列表设置为只读

Sharepoint 2010 - 如何创建具有多个过滤器的报告,例如用户使用情况报告

Sharepoint 使用工作流更改 Sharepoint Designer 中的内容类型

c# - 将 SharePoint 文件夹和内容移动到同一文档库中的不同位置

c# - 最近的事件 Webpart sharepoint 2010?

c# - Linq 选择项目直到下一次出现

c# - 如何以存储库模式读取 iCollection 数据 - ASP.NET- MVC Entity Framework

c# - WPF+Caliburn.Micro : ComboBox and ListBox not updating with dictionary properly

sharepoint - 将凭据传递给 Word Interop 以在 SharePoint 中打开文档