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 facing 2 problems when I'm deploying my solution in QA environment.

Scenario 1:

  1. I have written a feature (Feature 1) to create custom list (say List 1). When feature 1 is activated, List 1 is getting created.

  2. I have written another feature (Feature 2) thru which I am attaching “ItemUpdated” event to List 1. Feature 2 is getting activated and event is attached to List 1 successfully. (I confirmed this using ULS Logs)

Problem 1: When I update item in List 1 Item Updated event is not firing.


Scenario 2:

  1. I have document library already created in my sub site.

  2. I have written feature (feature 3) thru which I am attaching “ItemAdded” event to this document library. Feature 3 is getting activated and event is attached to document library successfully. (I confirmed this using ULS Logs)

Problem 2: When I add new item to document library Item Added event is not firing.


Please let me know if I'm missing something here?

Events are attached to the lists. I have confirmed by running following powershell command:

$w = Get-SPWeb -identity "My site URL"
$l = $w.Lists["My List Title"]
$l.EventReceivers
share|improve this question
    
what is written in your Elements.xml event receiver file ? –  Alex Choroshin Apr 10 '13 at 11:45

2 Answers 2

I can suppose that your event is attached before your list is created and SharePoint just have no reference to execute this. Do you create an instance of the list?

Try to see with Sharepoint Manager if event receivers are attached well to your list.

To attache event receiver:

1) install your list feature, activate and check that list is created.

2) Install the second feature with event receivers and add event receiver on FeatureActivated event using following:

SPList list = web.GetListByUrl(urlList);

Assembly assembly = Assembly.GetExecutingAssembly();
string eventReceiverAssembly = assembly.GetName().FullName;

/* Item Added */
SPEventReceiverType eventReceiverType = SPEventReceiverType.ItemAdded;
DeleteEventReceiverIfAlreadyExist(list, eventReceiverClass, eventReceiverAssembly, eventReceiverType);
SPEventReceiverDefinition eventReceiverDefinition = list.EventReceivers.Add();
eventReceiverDefinition.Name = eventReceiverName;
eventReceiverDefinition.Type = eventReceiverType;
eventReceiverDefinition.Assembly = assembly.GetName().FullName;
eventReceiverDefinition.Class = eventReceiverClass;
eventReceiverDefinition.Update();

public static void DeleteEventReceiverIfAlreadyExist(SPList list, string eventReceiverClass, string eventReceiverAssembly, SPEventReceiverType eventReceiverType)
        {
            foreach (SPEventReceiverDefinition definition in list.EventReceivers)
            {
                if (definition.Class == eventReceiverClass && definition.Assembly == eventReceiverAssembly && definition.Type == eventReceiverType)
                {
                    definition.Delete();
                    list.Update(true);
                    break;
                }
            }
        }

3) Go and activate your second feature

Hope it helps,

andrew

share|improve this answer

I ran into a situation just like yours. The problem for me was that the assembly being referenced by the event receiver did not match the assembly stored in the GAC. Check the properties of the list item receiver's four part assembly name via Sharepoint Manager and ensure that the assembly actually exists in the GAC.

If it doesn't exist, then that would be the reason the event doesn't get fired.

Good luck

share|improve this answer

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.