shieldguy
asked on
How to assign permission to a list programmatically using SharePoint 2007 object model
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[newlyCreatedList GUID];
newlyCreatedList.BreakRole Inheritanc e(false);
SPUser oUser = web.SiteUsers["win2008DevB \\Administ rator"];
// 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.
objRoleAssign.RoleDefiniti onBindings .Add(objWe bRoleDefn[ "Read"]);
newlyCreatedList.RoleAssig nments.Add (objRoleAs sign);
newlyCreatedList.Update();
As the above code assign read permission to Administrator, but Administrator can still add and delete items.
Any suggestions?
SPList newlyCreatedList = web.Lists[newlyCreatedList
newlyCreatedList.BreakRole
SPUser oUser = web.SiteUsers["win2008DevB
// assign Role to the defined User
SPRoleDefinitionCollection
SPRoleAssignment objRoleAssign = new SPRoleAssignment(oUser);
// specify the name of the role definition like [Full Control][Read][Contribute]
objRoleAssign.RoleDefiniti
newlyCreatedList.RoleAssig
newlyCreatedList.Update();
As the above code assign read permission to Administrator, but Administrator can still add and delete items.
Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks