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).