Event in question is item added event, and I am updating (systemupdate) same item multiple times.
Behind the scene:
- Site is multilingual (English,french,spanish)
- List item variation propagation is enabled, so I believe event receiver will fire multiple times once with w3wp process, and twice with owstimer.(Correct me if I am wrong)
- Sole purpose of event receiver is to break the role inheritance of list item and reassign some permissions after iterating through site groups.
code:
try
{
this.EventFiringEnabled = false;
string siteurl = properties.WebUrl;
SPListItem _currentItem = properties.ListItem;
int itemid = _currentItem.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(siteurl))
{
using (SPWeb web = site.OpenWeb(properties.ListItem.Web.ID))
{
if (properties.ListItem.ModerationInformation != null && properties.ListItem.ModerationInformation.Status == SPModerationStatusType.Approved && properties.ListItem.Level == SPFileLevel.Published)
{
web.AllowUnsafeUpdates = true;
SPList myList = web.Lists.TryGetList("listName");
SPListItem item = myList.GetItemById(itemid);
//fetch some values from item object
foreach (string value in collection)
{
if (!item.HasUniqueRoleAssignments)
{
//break item role inheritance
item.SystemUpdate(false)
}
//logic to add permissions to the item
item.SystemUpdate(false)
// there are n number of permissions so item.systemupdate is called multiple times
//logic to add permissions to the item
item.SystemUpdate(false)
//logic to add permissions to the item
item.SystemUpdate(false)
//logic to add permissions to the item
item.SystemUpdate(false)
}
Event Firing is disabled at the start of event receiver but still sometimes I found it to true at the later stage.
Item I am updating is on the same list on which the event receiver is firing.
I am getting save conflict errors at various item.SystemUpdate()
Please suggest!