Object model to change item-level permission for a blog posts list
Question:
By default, blog posts in a blog site can be deleted or edited by anyone. How can I, using object model, restrict such that only owners can edit/delete. I would also like to do the same for comments list.
Currently, we can do that manually by going into "List Settings > Advanced Settings" and changing the item-level permissions. I would like to do the same thing but using object model so that I can automate this process. What is the API that I can use?
Answer:
Finally, I was able to get them working:
The way you get the reference to SPList object makes a difference.
If you have "Posts" list and want to set the writesecurity.
Below code does NOT work
-------------------------------
bl.Lists["Posts"].WriteSecurity = 2;
bl.Lists["Posts"].Update();
-------------------------------
However, this code works:
-------------------------------
SPList postsList = bl.Lists["Posts"];
postsList.WriteSecurity = 2;
postsList.Update();
-------------------------------
More information: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.writesecurity.aspx
Similarly, there is ReadSecurity.
SPList.WriteSecurity Property:
Type: System.Int32
-
1 — All users can modify all items.
-
2 — Users can modify only items that they create.
-
4 — Users cannot modify any list item.
This posting is provided "AS IS" with no warranties, and confers no rights.
浙公网安备 33010602011771号