Code:
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
string strTitle = string.Empty;
using (SPSite site = new SPSite(properties.WebUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list =
web.Lists[properties.ListTitle ];
SPListItem item =
list.GetItemByIdSelectedFields(properties.ListItemId, "Title");
strTitle = (String)item.DisplayName ;
}
}
Working with BeforeProperties and AfterProperties on SPItemEventReceiver
Here are the results for a list:
List
|
BeforeProperties
|
AfterProperties
|
properties.ListItem
|
ItemAdding
|
No
value
|
New
value
|
Null
|
ItemAdded
|
No
value
|
New
value
|
New
value
|
ItemUpdating
|
No
value
|
Changed
value
|
Original
value
|
ItemUpdated
|
No
value
|
Changed
value
|
Changed
value
|
ItemDeleting
|
No
value
|
No
value
|
Original
value
|
ItemDeleted
|
No
value
|
No
value
|
Null
|
No value means that column value in the
hash table was not available.
New value means that the correct value for the column was available.
Changed value means that the correct updated value was available.
Original value means that the correct original value was available.
New value means that the correct value for the column was available.
Changed value means that the correct updated value was available.
Original value means that the correct original value was available.
Here is the same test against a document library:
Library
|
BeforeProperties
|
AfterProperties
|
properties.ListItem
|
ItemAdding
|
No
value
|
No
value
|
Null
|
ItemAdded
|
No
value
|
No
value
|
New
value
|
ItemUpdating
|
Original
value
|
Changed
value
|
Original
value
|
ItemUpdated
|
Original
value
|
Changed
value
|
Changed
value
|
ItemDeleting
|
No
value
|
No
value
|
Original
value
|
ItemDeleted
|
No
value
|
No
value
|
Null
|
Properties.ListItem refers the the current value for the list item at that point in the event. Null means that the item is not available. My analysis yields the following results:
- Not surprisingly, we get null values for for ItemAdding (before item is added) and ItemDeleted (after item is deleted).
- As correctly documented in the SDK, item events for lists do not expose BeforeProperties.
- ItemAdding and ItemAdded correctly report the value in the AfterProperties for an list item, but not a library item. This is curious.
No comments:
Post a Comment