As in my last blog, I've been developing with SharePoint 2007 in the last few months, and specifically working with SharePoint events, and Event handling on lists. My last blog, I posted my results of the order of events, and the results. I only tested the event order on a task list, a custom list and a document library. I didn't think to test it on other types of lists, but I guess I should have. I have had a few people point out some quirky behavior with events on different types of lists.
This is what I have so far.
Custom List or Task List - When updating, manipulating the Title column in the ItemAdding event on this list, and then calling the SPListItem method, Update, the results don't seem to get saved. An example, let's say you want to append the date to the title of each announcement before it gets save, in the ItemAdding event. You can write code like I have below, but it simply doesn't update it. I haven't stepped through it, and seen but it doesn't look like it has any effect. (Thanks to Sahil Malik)
|
SPListItem item = properties.ListItem;
string mynewtitle = item["Title"].ToString();
item[ "Title"] = mynewtitle + DateTime.Now.ToString();
item.Update(); |
Picture Library - This was an bizarre result, in the Wiki Library next there is an missing set of events, from what I would expect the behavior to be. In the Picture library, there are extra events firing. These are the results, of adding an Picture to a picture library and me tracking the events.
>
|
Adding -
Picture Library - ItemAdding - 10:32:42 PM Picture Library - ItemAdding - 10:32:42 PM Picture Library - ItemAdding - 10:32:42 PM Picture Library - ItemAdded - 10:32:42 PM
Updating - Picture Library - ItemUpdating - 10:32:53 PM Picture Library - ItemUpdating - 10:32:53 PM Picture Library - ItemUpdating - 10:32:53 PM Picture Library - ItemUpdated - 10:32:53 PM |
You noticed that the ItemAdding and the ItemUpdating fire an extra 2 times when either Adding or Updating an item. I'm wonder if this is because of how a picture library functions, and the thumbnail needs to be generated, or something to that effect, but it is a very unusual behavior, and if you are doing anything in this pre-synchronous events, you need to be aware of this, and code appropriately, to take this into account.
Wiki Library - This one is very interesting. I haven't played with Wiki Libraries very much in Beta 2, or in SharePoint 2007 at all really. I got an email from Nick Swan, and he pointed out his results, that he wasn't able to add an announcement every time a page was added. I looked at the Events that fired for a Wiki Library, and when you add a page, the ItemAdded and the ItemAdding events, simply don't fire. The work around, would be to use the ItemUpdating and the ItemUpdated, and use some logic to guess it the Item was added in the last few minutes, but a really kludgy work around I think. I'm not sure if this is design, or an oversite in Beta 2, or how it will work with Office 2007 comes out.
This are just the quirks I have found so far, and I will keep looking. Let me know if any of you find anything, thanks.
Morgan
posted @ Tuesday, August 01, 2006 10:54 PM