SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 ?

share|improve this question
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 '12 at 13:04
up vote 1 down vote accepted

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.

share|improve this answer
Thanks Alexander. – Shahid Nov 22 '12 at 4:10

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;
share|improve this answer

Your Answer


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.