SharePoint 2010 has many wonderful improvements over previous versions. One of which is a vastly improved Content Deployment mechanism and API.
If your application makes use of Event Receivers or Feature Receivers, these can, depending upon what they do, cause problems during a Content Deployment job. If you have code that you’d rather not execute when your event is triggered as a side effect of a Content Deployment job, you can use the SPImportContext object to find out if a job is running, and if so, to take alternative action.
Here’s an example on an ItemAdding Event Receiver (you’ll also need a using statement referring to the Microsoft.SharePoint.Deployment namespace)
1: /// <summary>
2: /// An item is being added.
3: /// </summary>
4: public override void ItemAdding(SPItemEventProperties properties)
5: {
6: if (!SPImportContext.Current.IsRunning)
7: {
8: //TODO: add event receiver code here
9: base.ItemAdding(properties);
10: }
11: }
If you miss this out this check in an Event Receiver or Feature Receiver, you might cause deadlocks or spurious List Items that you did not intend.
You can leave a response, or trackback from your own site.

Hi Joel,
I have to use the same code for MOSS and 2010 , that is clients requirement.
Now if i use ImageUrl in CustomActionGroup , wsp for moss would not be deployed because ImageUrl in CustomActionGroup will break the schema. Client want’s to have ImageUrl for 2010 and without that for MOSS. So is there any way through which ‘during deployment’ i can figure out which feature to deploy and which to ignore ?.
I can create two features one with imageUrl and one without now its matter of ignoring one after getting the “12″ or “14″.