How to assign permission to a list programmatically using SharePoint 2007 object model
Posted on 2011-09-09
How do we assign a permission to a list so that one sharePoint group have 'Full Control' and rest of the AD/SharePoint users have 'Read' . I have tried using the following lines of code but this doesn't seem to be working.
SPList newlyCreatedList = web.Lists[newlyCreatedListGUID];
SPUser oUser = web.SiteUsers["win2008DevB\\Administrator"];
// assign Role to the defined User
SPRoleDefinitionCollection objWebRoleDefn = web.RoleDefinitions;
SPRoleAssignment objRoleAssign = new SPRoleAssignment(oUser);
// specify the name of the role definition like [Full Control][Read][Contribute] etc.
As the above code assign read permission to Administrator, but Administrator can still add and delete items.