views:

157

answers:

2

Hi,

I'm using ItemAdding Event for one of my SPLists. The question is how I can get the new not yet added item from SPItemEventProperties? I've tried to ListItem.Item but the debuger shows that the property is set to Nothing. Any correction suggest?

Best Regards

T.S.

+3  A: 

Ihe ItemAdding event fires before a recored is actually added so you can't access the fields using .Item.

However you can access everything apart from ID (as its still not been created yet) in the .AfterProperties hash table.

Nice code sample

Ryan
+1  A: 

First of all, it depends on whether your event receiver is running on a List or a Document Library.

Check out this site for handy tables of when BeforeProperties, AfterProperties, and properties.ListItem are populated: http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?List=fcb287b5%2D7a1a%2D4206%2Da04f%2D2a97805e4a25&ID=25

Kit Menke
Interesting - I would never have guessed they worked slightly differently! I can't imagine why it would be but yet another SharePoint gotcha waiting to trip us up.
Ryan