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

Is it possible to prevent Sharepoint framework to call ItemUpdated event method, after ItemAdded? I want ItemUpdated to be called only when the item is edited. I don't want to let sharepoint call ItemUpdated after ItemAdded.

and/or

Is it possible to pass a parameter from ItamAdded to ItemUpdated event method?

share|improve this question
    
it looks like you have been trying to use incorrect approach. Could you describe your issue? –  Alexander Sep 16 '12 at 8:37
    
First I want to say that I am using a static variable to get a value in item updating method and I use it in item updated method (i'm doing the same for delete). I don't know if this will work for your case, but you can try it. I am waiting for your feedback. –  Tadreu Mar 6 at 13:22
add comment

1 Answer

For your first question, the answer is yes. If you are using SharePoint 2010, then you can use following code in the ItemAdded event to prevent ItemUpdated event being called:

    EventFiringEnabled = false;       
    //your code implementation       
    EventFiringEnabled = true;

If you are using MOSS 2007, you can use following code

   DisableEventFiring();
   //your code implementation
   EnableEventFiring();

For the second question, I don't think it is possible.

share|improve this answer
1  
For the second question you can use additional field in list item which should be hidden. But in my opinion, the behevior when the item updated event is invoked after item adding event is incorrect. I think that user10606 did something wrong. –  Alexander Sep 16 '12 at 9:15
    
sharepoint.stackexchange.com/a/45470/627 Basically the same –  eirikb Sep 16 '12 at 10:58
1  
@Alexander and how do you plan to persist a new value to that field? ;) calling Update()? and I dont think disabling event firing will keep itemUpdated from firing when adding a file. The reason ItemUpdate is called is that the provisioning of the file is a two step process: first the file is added, then the metadata (as i remember it). When adding publishing pages, ItemUpdated is called several times. Disabling event firing is ment to short circuit getting recursive loops when calling Update() in an ItemUpdated event receiver. –  Anders Rask Sep 16 '12 at 19:59
    
@AndersRask, the question does not contains information about type of item, thus I thought that this question is about typical list item, not a document. Also you are right, I mixed up ItemAdding and ItemAdded method. In the fist method you can use AfterProperties to set up value in the hidden field. –  Alexander Sep 16 '12 at 20:55
    
Have you tried this? Im pretty sure you cant set them (they are only get properties) other than by setting a value in the field itself. It might work, but before/after properties work differently on different types of items, and often not the way you would expect... –  Anders Rask Sep 16 '12 at 21:04
show 2 more comments

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.