Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
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 '10 at 19:46
    
Please mark this post with answer as it has been resolved. –  Anonymous Apr 26 '10 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 –  Anders Rask Apr 26 '10 at 22:02
    
Ah and it is you that ask the question that can set it as answer –  Anders Rask Apr 26 '10 at 22:04
    
This item has been resolved. Mark it with complete status. Thanks –  Anonymous May 7 '10 at 18:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.