Link to home
Start Free TrialLog in
Avatar of shieldguy
shieldguyFlag for United Kingdom of Great Britain and Northern Ireland

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[newlyCreatedListGUID];
                        newlyCreatedList.BreakRoleInheritance(false);

                        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.
                        objRoleAssign.RoleDefinitionBindings.Add(objWebRoleDefn["Read"]);
                        newlyCreatedList.RoleAssignments.Add(objRoleAssign);
                        newlyCreatedList.Update();

As the above code assign read permission to Administrator, but Administrator can still add and delete items.
Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of chapmanjw
chapmanjw
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shieldguy

ASKER

Yeah the Administrator was the site collection administrator that's why it had full control on the list even though I assign the read permission. I then tried by creating another user in windows and applied the permissions to it which worked fine.
Thanks