Solved

How to assign permission to a list programmatically using SharePoint 2007 object model

Posted on 2011-09-09
2
432 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:shieldguy
2 Comments
 
LVL 21

Accepted Solution

by:
chapmanjw earned 500 total points
ID: 36514864
Is the Administrator user a Site Collection Administrator?  Or have they been assigned Full Control permission in the User Policy for the web application in Central Admin? (Under Operations > User Policy on right side)
0
 
LVL 1

Author Closing Comment

by:shieldguy
ID: 36534617
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
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft SharePoint Foundation 2010 and Microsoft SharePoint Server 2010 do not offer the option to configure the location of the SharePoint diagnostic trace log files during installation.  This can, however, be configured through Central Administr…
SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question