When a new item is created it will have the same permission as the list (list inherits permission from the site) unless you explicitly break them.
To break the inheritance from the parent container, use "BreakRoleInheritance". Set function param to "true" if you want to retain the access control but break the inheritance. If function param is "false", then feature (SPListItem etc) will not have any access control.
"Operation is not valid due to the current state of the object" error when calling "BreakRoleInheritance" for SPListItem occurs if you have a new list item and have not called the update method.
Correct way of using function:
SPListItem newItem = new SPListItem();
newItem["Title"] = "My Item Title";
newItem.Update();
newItem.BreakRoleInheritance(false);
newItem.Update();
Note: When you use the BreakRoleInheritance function, the AllowUnsafeUpdates property of SPWeb is automatically set to false.
Subscribe to:
Post Comments (Atom)
Thanks!!
ReplyDeleteThanks from me too ;)
ReplyDeleteSave my time. Thank you!
ReplyDeleteThanks my friend. Save my time!
ReplyDelete