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

How to add Event Receiver to two lists. One must be actualizing when in the secound element add's.

I Use public override void ItemAdding(SPItemEventProperties properties)

But what should i put in this method ?

share|improve this question

1 Answer 1

Grzegorz,

What happens with Event Receivers, in the receiver in feature XML has a ListTemplateId which determines to which List template the event receiver is for... So lets say you need to add event receiver on custom list then ListTemplateId=100 or you want to add to Announcements template the ListTemplateId=104, like below:

`<Receivers ListTemplateId="100">`

Now if you attach event receiver to custom list template, the event will fire for every custom list you have in the scope! And you can identify the list in code by using properties... the SPItemEventProperties has a property called List.. which give you SPList, and you can either by GUID or Name identify the list and perform operation accordingly... What I do is create a SWITCH-CASE for different lists and perform operations according in the cases!

I hope this answered and clarify the concept of Event Receivers, you can read more over here and here

So when you have deployed the event receiver it will fire for both the lists, and you will first identify for which list it has been fired.. then code accordingly!

Arsalan Adam Khatri
Blog: http://arsalkhatri.wordpress.com

share|improve this answer
    
Thanks for replay :) But how tu choose one list too add another list? –  Grzegorz Z Oct 15 '12 at 9:32
    
I cant understand this: "the SPItemEventProperties has a property called List.. which give you SPList,", how I can do It ? –  Grzegorz Z Oct 15 '12 at 9:43
    
I wont only add one list to another –  Grzegorz Z Oct 15 '12 at 9:48
    
You have this public override void ItemAdding(SPItemEventProperties properties) right? If you write properties.List you have the list for which the event receiver is called –  Arsalan Adam Khatri Oct 15 '12 at 9:48
    
sorry, what you mean by "actualizing when in the secound element add's" or "I wont only add one list to another" ? –  Arsalan Adam Khatri Oct 15 '12 at 9:49

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.