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'm having trouble binding my event receiver (ItemAdding) event to a specific list. I created a Feature Receiver and tried both the GUID and Name. But, I have another list that uses the same column name that I am trapping for as the list I want to bind to, so it seems the event trips in this other list as well. I thought the Feature Receiver would prevent this. Here is how Im attempting this:

Public Overrides Sub FeatureActivated(ByVal properties As SPFeatureReceiverProperties)
    Try
        'Get a Reference to the Current Web
        Dim oWeb As SPWeb = properties.Feature.Parent

        'Get a Reference to the PEEIT%20StateLicenses List (Using the Lists Guid)
        Dim oGUID As New Guid("{26712059-15E5-48A6-A26D-8A9A521418CF}")
        'Dim oList As SPList = oWeb.Lists(oGUID)
        Dim oList As SPList = oWeb.Lists("PEEIT State Licenses")
        Dim sAssembyName As String = "WEC.SPS.Feature.SR558,Version=1.0.0.0,culture=neutral, PublicKeyToken=9c6f26b52f1522b5"
        Dim sReceiverName As String = "WEC.SPS.Feature.SR558.EnforcePEEITListIntegrity"

        'Attach Event Receiver to Specific List (PEEIT%20StateLicenses List)
        oList.EventReceivers.Add(SPEventReceiverType.ItemAdding, sAssembyName, sReceiverName)
    Catch ex As System.Exception
        'Throw a message in the ULS Logging
        Microsoft.Office.Server.Diagnostics.PortalLog.LogString("Exception Occurred on SR558-FeatureActivated: {0} || {1}", ex.Message, ex.StackTrace)
    End Try

Bismarck

share|improve this question
add comment

3 Answers 3

To do that you have just an only way: you must check the name of the list. You can check this name in two ways: 1 - Check the name by code (you can read the list name or list title):

properties.ListItem.Name
properties.ListItem.Title

2 - In the file Elements.xml change the following line:

<Receivers ListTemplateId="xxx">

Where xxx is a number with the following:

<Receivers ListUrl="Lists/TestAnnouncements">
share|improve this answer
add comment

There's known tool that can do it - http://sharepointforum.com/Documents/Useful%20Files/EventHandlerExplorer.zip. It's a project in Visual Studio so you can not only use this tool to attach your receiver to single list instance but see how to do it in code. :)

share|improve this answer
add comment

You can change in "Receivers" tag in "Elements.xml " as "Receivers ListTemplateId="someNumber" to "Receivers ListUrl="Lists/yourListName".

share|improve this answer
add comment

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.