Solved

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

Posted on 2011-09-09
2
420 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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The Scenario: Let’s say you have a quote worksheet in Excel that you use to work up sales figures and such for your clients. You utilize SharePoint to manage and keep track of these documents. You would like values from your worksheet to populate Sh…
There is one common problem that all we SharePoint developers share: custom solution deployment. This topic can't be covered fully in this short article, so all I want to do in this one is to review it from a development-to-operations perspectiv…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now