Solved

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

Posted on 2011-09-09
2
429 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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