sharepoint-2013event-receiver

sharepoint 2013 itemupdated with argumentOutOfRangeException


I'm facing an issue with sharepoint 2013 and an event receiver itemupdated. In this event, i move item to an other library with

properties.ListItem.File.MoveTo(Url + "/" + properties.ListItem.File.Name);

I try too with this at begining but without success

this.EventFiringEnabled = false;

It goes correctly till the correct library but i receive an error sharepoint with a correlationID

Regarding log with correlationID , i get an error

Unexpected  System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. 

i tested synchronous or not

It seems that sharepoint try to reload the form edit but the item has moved to an other library

Thanks for your help


Solution

  • i think, to make it work, you should retrieve new object from the list and perform the operation there.

    something like

    var item = properties.List.GetItemByID(properties.ListItemId);
    item.File.MoveTo(Url + "/" + item.File.Name);
    

    SPItemEventProperties doesn't like when you're messing with his internal elements (dispose, move, delete etc.)