Setting/Changing item level permissions in SharePoint Event Receiver:


      public override void ItemAdded(SPItemEventProperties properties)
       {
           SPWeb web = properties.Web;
           SPListItem listItem = properties.ListItem;
          

           //get the username from list item people picker
           string accName = listItem["Name"].ToString();
           SPUser user = web.EnsureUser(accName);

           listItem.BreakRoleInheritance(false);
           SPRoleDefinitionCollection webroledefinitions = web.RoleDefinitions;
           SPRoleAssignment roleassignment = new SPRoleAssignment(user);
           //Set Read permission

           roleassignment.RoleDefinitionBindings.Add(webroledefinitions["Read"]);
           listItem.RoleAssignments.Add(roleassignment);

           listItem.SystemUpdate(false);
       }

Comments

Popular posts from this blog

Copilot Studio Azure OpenAI with SharePoint Data Source

Create and Deploy custom copilot to SharePoint Site (Part 2)

Copilot Announcements from Microsoft Build 2024