I have only 1 Visual Studio Project.

It contains 1 EventReceiver(for DocumentLibrary) and multiple-WebParts. I have defined the Scope=Site of Feature.xml file of Project.

I have created 1 custom function in EventReceiver, which calls on Every event is fire either Add/Update/Delete in my DocumentLibrary.

When I deploy it by rightclicking on the project, Everything is working fine but When I create any page or any item is added into my any CustomList then also the EventReceiver is fires. Although it is created on DocumentLibrary. Its not giving me any error, but I dnt want to call it again.

But when I Debug the Project by F5, then I am getting error in EventReceiver, because its called multiple times means on every event.

If I deploy the EventReceiver's Scope=Web, then might be it will solve the problem, but I need to deploy the WebParts also with Scope=Site.

So How to solve this problem by single deployment ?

  • Does your event receiver update the item that caused the event to happen, and did you disable event firing in your code before updating that item? Could that be the issue?
    – Andy Burns
    Nov 21, 2012 at 13:04

2 Answers 2


You can add second feature to the project. In this case you will have one solution package with two features (first is a site scoped feature, second is a web scoped feature). In a site scoped feature you can include your web parts. To do it you should click on Features folder and select add new feature option.


I suspect you've bound the event receiver to the Document Library template, which your custom list may also be using, therefore the event receiver is bound to both list instances.

If I need to bind an event receiver to a specific list then I do so in code, usually via Feature Activation and codd like this:

    protected static void AddEventReceiverToList(string name, string className, SPList list, string assemblyName, SPEventReceiverType eventReceiverType, SPEventReceiverSynchronization eventReceiverSynchronization)
        if (name == null) throw new ArgumentNullException("name");
        if (className == null) throw new ArgumentNullException("className");
        if (list == null) throw new ArgumentNullException("list");
        if (assemblyName == null) throw new ArgumentNullException("assemblyName");
        SPEventReceiverDefinitionCollection eventReceiverDefinitionCollection = list.EventReceivers;

        foreach (SPEventReceiverDefinition eventReceiverDefinition in eventReceiverDefinitionCollection)
            if (eventReceiverDefinition.Name == name)

        SPEventReceiverDefinition eventReceiver = eventReceiverDefinitionCollection.Add();
        eventReceiver.Name = name;
        eventReceiver.Synchronization = eventReceiverSynchronization;
        eventReceiver.Type = eventReceiverType;
        eventReceiver.Assembly = assemblyName;
        eventReceiver.Class = className;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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