Event Receivers and Content Deployment Jobs

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.


  1. says

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

  2. Maninder says

    Hi ,
    I would be great help if you could guide me through the following situation .

    I am using content deployment Job and the target of content deployment job is having an event receiver on a specific list that moves items to another site collection(Added,Updated,Deleted).
    Everything works fine when i am adding manually event receiver is working fine. But when content deployment job is migrating content .event receiver is not firing ,can u please share your views on the same .

    Thanks in advance.

  3. Maninder says

    Hi Joel Thanks for your reply , Can you please guide me through the following situations ,i am managed to solve the previous issue regarding event firing using STSADM command: STSADM -o editcontentdeploymentpath -pathname Interaktor-Replication-Path -enableeventreceivers yes

    After this event starts firing ItemAdded events works fine but on itemUpdated when i am trying to get Properties.listItem i am getting strange results .The list for listitem is not my list on which it should fir event e.g Images list i am able to get a list name as “Fast Buffer Profiles” .So this is breaking the whole functinality.

    It would be a great help for any comments on the same.
    Thanks in Advance

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>