1

I am adding custom meta-data to item that user uploaded

item["Title"] = "My Title";
item["Column1"] = "column1";
item.Update();

When I comment out the item.Update() then the itemUpdated event does not fire twice. How can I add additional custom meta-data (in addition to whatever else end user is adding from the front-end)? I have to use ItemUpdated event handler.

1 Answer 1

1

The reasons for it firing twice can be several; one common is that your call to Update makes the receiver fire once again. Use the DisableEventFiring to prohibit the Update within your receiver to trigger another event.

5
  • Thank you Wictor. You have solved my hours of migrant. LOL. To prevent for ever loop you can call DisableEventFiring() and then EnableEventFiring(). A Sample code: public override void ItemUpdated(SPItemEventProperties properties) { //some handling here ListItem item = properties.ListItem; item["someproperty"] = "some value"; this.DisableEventFiring(); //save changes addedItem.Update(); this.EnableEventFiring(); } THIS WORKS LIKE CHARM....
    – Anonymous
    Apr 26, 2010 at 19:46
  • Please mark this post with answer as it has been resolved.
    – Anonymous
    Apr 26, 2010 at 19:46
  • 1
    Remember to put the disable/enable code inside a try/finally, so that event firing is enabled if you encounter an exception Apr 26, 2010 at 22:02
  • Ah and it is you that ask the question that can set it as answer Apr 26, 2010 at 22:04
  • This item has been resolved. Mark it with complete status. Thanks
    – Anonymous
    May 7, 2010 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.