Solved

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

Posted on 2011-09-09
2
433 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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