Sharepoint 2010 Event Recevier: Attach An Event Recevier To A Custom List


– In Solution Explorer open “Elements.xml”

– Replace the attribute “ListTemplateId” with “ListUrl” and add your url as value:

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”
http://schemas.microsoft.com/sharepoint/”>
<Receivers ListTemplateId=”100″>
<Receiver>
<Name>EventReceiver1ItemAdding</Name>
<Type>ItemAdding</Type>

-> replace

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”
http://schemas.microsoft.com/sharepoint/”>
<Receivers ListUrl=”/Lists/CUSTOMLISTNAME”>
<Receiver>
<Name>EventReceiver1ItemAdding</Name>
<Type>ItemAdding</Type>

Tip:

To use an event recevier for two or more lists, you have to add one more “<Receviers>” node

Sample:

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”
http://schemas.microsoft.com/sharepoint/”>
<Receivers ListUrl=”/Lists/CUSTOMLISTNAME_1”>
<Receiver>
<Name>EventReceiver1ItemAdding</Name>
<Type>ItemAdding</Type>
<Assembly>MYEVENT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7f04562e6a15ae2a</Assembly>
<Class>MYEVENT.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>

<Receivers ListUrl=”/Lists/CUSTOMLISTNAME_2”>
<Receiver>
<Name>EventReceiver1ItemAdding</Name>
<Type>ItemAdding</Type>
<Assembly>MYEVENT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7f04562e6a15ae2a</Assembly>
<Class>MYEVENT.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
</Receiver>
</Receivers>

</Elements>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s