I want to thank Ulrich Strauss for helping me find the work around for the recursion of the SharePoint events on a list.
Apparently, there is a set internal recursion depth of 10 in the SharePoint event model, so if for some reason, you want an ItemUpdating or ItemUpdated event to update the item you are working on, and you want to keep calling it self, you will have to figure out a work around because you can only go to 10 levels deep.
The problem I was attempting to get around was this.
I've created an event handler for a list, and I have a hidden column on each item, that keeps a type of audit log of the item. I know I could use the Change Log, but I want to control what gets written and when. I created an Event Handler for the ItemAdded and ItemUpdated events, to write the audit log information in. The problem, when I updated an item it would fire the events again and again, 9 times more. This is where Ulrich let me know that internal recursion depth for events is 10, because the events fire in the app-pool for the site, and you don't want to hang a site with an infinite loop.
Here is the work around code
public
override void ItemUpdated(SPItemEventProperties properties)
{
this.DisableEventFiring();
SPListItem item = properties.ListItem;
string history = item["AuditHistory"].ToString();
item["AuditHistory"] = history + "\n" + properties.ListItemId + "updated at " + DateTime.Now;
item.Update();
this..EnableEventFiring();
}
So that will get around updating an item from the ItemUpdated, or ItemUpdating events.
I have been debugging different events, and I've noticed there are a lot of properties that have no information in them at all. I'm not sure if it because it is Beta 2, or this is by design. Here are a few examples.
ItemAdding event - There is no ListItem object from the SPItemEventProperties object. I wouldn't expect an ID, because the item hasn't been added, but how do you get the value of the item, there is nothing in the AfterProperties or BeforeProperties.
ItemUpdated event - I've haven't found any event that has data in the ReceiverData object of the SPItemEventProperties.
I hope this issues get resolved before TR and defintly before production. I like the new power of WSS/MOSS 2007, but if the tools for developing as a platform are incomplete, or bugging it is going to be a lot of finding the workarounds similar to how it was with SharePoint 2003.
Morgan
posted @ Tuesday, August 15, 2006 10:22 AM