1

I am trying to break the inheritance of the current item and assign the new ones . I tried it using ItemAdded and it worked but the problem was it was taking time to assign the new permissions to the user and users were getting error after opening that item , it was opening after refreshing the page . so i tried putting 'synchronize' in the xml file but still it dint work . so my last resort i thought would be to go ahead with ItemAdding ,

In ItemAdded : i was doing it this way

SPListItem ListItem = Web.Lists[properties.ListId].GetItemById(properties.ListItem.ID);
oWeb.AllowUnsafeUpdates = true;
 ListItem.BreakRoleInheritance(true);

SPRoleAssignmentCollection SPRoleAssColn = ListItem.RoleAssignments; 

for (int i = SPRoleAssColn.Count - 1; i >= 0; i--) 

{
SPRoleAssColn.Remove(i);
}

but i am not able to get the current item in ItemAdding event so how can i break inheritance and assign new ones in this event.

5 Answers 5

1

As you said it yourself in the question that the item has not yet been created hence you won't be able to get the item using properties.Item.

If you need to get the values of the columns then you would need to use

properties.AfterProperties["ColumnName"]

the statement SPListItem item = properties.Item would yield result for you in the ItemAdded event as by then the item would have been already created.

1
  • ,i editted my question can you suggest on this. Commented May 3, 2016 at 7:06
1

You cannot get the item value in ItemAdding event. You can refer this BeforeProperties/AfterProperties in Event Receivers.

You can get the Value in ItemAdded event.

Let me know your thoughts.

Thanks

1
  • @Akshay Morya , i editted my question can you suggest on this. Commented May 3, 2016 at 7:05
1

Just be sure to get the values from ItemAdded event. Because when ItemAdding, the current item is not updated in the list yet and you cannot get the item values. The reason why that the values are not available is because they aren't exist yet.

1
  • @Mohammad Arif , i editted my question can you suggest on this. Commented May 3, 2016 at 7:06
1

Just to speed up the code in ItemAdded event, you can pass ListItem.BreakRoleInheritance(false); - false flag will not inherit user/ groups from parent so for loop will be avoided. Later you can just start assigning roles to required users.

0

It is not possible by using Sandbox or Farm solution. You can accomplish this using a workflow using AppStep.

Please refer the link for creating the workflow using AppStep

Or else try to refresh the page programattically at the end of the ItemAdded event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.