Howdy,
Still in the learning process with SharePoint.
We have an SPItemEventReceiver compiled into its own assembly.
We are using STSDev to package up a SharePoint solution with this EventReceiver as a feature. I am not assigning the SPItemEventReceiver to a specific ListTemplateId within the elements.xml, but am instead linking a ReceiverAssembly in the feature.xml and programmaticaly assigning the SPItemEventReceiver to multiple SPList items.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
foreach (SPWeb web in site.AllWebs)
{
SPListCollection webListCollection = web.Lists;
foreach (SPList myList in webListCollection)
{
if (myList.Title == "Lab Reports")
{
SPEventReceiverDefinitionCollection receivers = myList.EventReceivers;
SPEventReceiverDefinition receiver = receivers.Add();
receiver.Name = "PostUpdateLabReport";
receiver.Assembly = "LabReportEventHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111";
receiver.Class = "LabReportEventHandlers.LabReportsHandler";
receiver.Type = SPEventReceiverType.ItemUpdated;
receiver.Update();
break;
}
}
web.Dispose();
}
}
I am using FeatureDeactivating to do the reverse of the above code, removing the EventReceiver from the lists.
Question:
How should I handle the future event where LabReportEventHandlers is updated and the version changes?
These are the options I can think of:
Deactivate / Reactivate feature -- I would wrap the updated dll back into the SharePoint solution file, change my code above to reflect the new version, and use stsadmin to upgrade the solution. I would then deactivate/ reactivate the feature.
Add Assembly redirection to the web.config.
Don't bump the LabReportEventHandlers version number.
Is there something in changing the solution version that will help me?
I think there are problems with the 3 options:
After deactivation of the feature, someone could update an item before I can reactiave.
I would not want to edit the web.config by hand, so I would use the sharepoint API instead. Where would I run that code?
This is just plain wrong, but easy.
Hope you enjoy the question more than I enjoy SP. (SP and I have a love/hate relationship)
Thank you,
Keith