1

I have a feature which I have placed in the onet.xml in to make it active whenever the site collection is created. The feature contains two event receiver definitions for permission groups. One is for user added and the another is for user deleted. My problem is that when I create new site I find that feature activated but only event receiver definition for user added gets bound, to bind the other definition I have to manually re-activate the feature.

My code is:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        try
        {
            SPSite site = properties.Feature.Parent as SPSite;

            SPEventReceiverDefinition grpUserAdded = site.EventReceivers.Add();
            grpUserAdded.Name = "Event Receiver Group User Added";
            grpUserAdded.Type = SPEventReceiverType.GroupUserAdding;
            grpUserAdded.Assembly = "BI.Lofbergs.Intranet.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69b498d2e06e66cd";
            grpUserAdded.Class = "BI.Lofbergs.Intranet.Business.EventReceivers.GroupUserAddedEvent";
            grpUserAdded.Update();

            SPEventReceiverDefinition grpUserDeleted = site.EventReceivers.Add();
            grpUserAdded.Name = "Event Receiver Group User Deleted";
            grpUserAdded.Type = SPEventReceiverType.GroupUserDeleted;
            grpUserAdded.Assembly = "BI.Lofbergs.Intranet.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69b498d2e06e66cd";
            grpUserAdded.Class = "BI.Lofbergs.Intranet.Business.EventReceivers.GroupUserAddedEvent";
            grpUserDeleted.Synchronization = SPEventReceiverSynchronization.Asynchronous;
            grpUserAdded.Update();
        }
        catch { }
        finally { }
    }

What should I do to get both definitions bound automatically.(i.e. when the feature is activated).

4
  • Are you using site template? Oct 31, 2013 at 13:27
  • Yes sir, I am using site template..
    – users1100
    Oct 31, 2013 at 13:30
  • I too had this issue and I too activated through code. Couldn't find any solution. Oct 31, 2013 at 13:37
  • OK Sir, if you get solution then please let me know.
    – users1100
    Nov 1, 2013 at 3:58

1 Answer 1

1

Your code is wrong, it's using the same variable name twice. It should be:

SPEventReceiverDefinition grpUserAdded = site.EventReceivers.Add();
        grpUserAdded.Name = "Event Receiver Group User Added";
        grpUserAdded.Type = SPEventReceiverType.GroupUserAdding;
        grpUserAdded.Assembly = "BI.Lofbergs.Intranet.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69b498d2e06e66cd";
        grpUserAdded.Class = "BI.Lofbergs.Intranet.Business.EventReceivers.GroupUserAddedEvent";
        grpUserAdded.Update();

        SPEventReceiverDefinition grpUserDeleted = site.EventReceivers.Add();
        grpUserDeleted.Name = "Event Receiver Group User Deleted";
        grpUserDeleted.Type = SPEventReceiverType.GroupUserDeleted;
        grpUserDeleted.Assembly = "BI.Lofbergs.Intranet.Business, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69b498d2e06e66cd";
        grpUserDeleted.Class = "BI.Lofbergs.Intranet.Business.EventReceivers.GroupUserAddedEvent";
        grpUserDeleted.Synchronization = SPEventReceiverSynchronization.Asynchronous;
        grpUserAdded.Update();

Your Answer

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

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