I need to use the relevant event receiver to tell if a document is being published, is this possible? I will settle for has 'just been published' - i.e. I have no preference between itemupdating and itemupdated.

What I've Tried

I've tried both itemupdating and itemupdated with the following code:

   private Boolean IsBeingPublished(SPItemEventProperties properties)
       Int32 beforeVersion, afterVersion;

       beforeVersion = Convert.ToInt32(properties.BeforeProperties["vti_level"]);
       afterVersion = Convert.ToInt32(properties.AfterProperties["vti_level"]);

       return beforeVersion == afterVersion;

This doesn't work, it's true most of the time so doesn't indicate whether it's been published or not.

Any help GREATLY appreciated. I need this to consistently tell me whether the event was fired because of a publish action or not.

  • +1 for the interesting question. Just a suggestion, you could see if reflector gives any hint - have a look at the publish function that is called from the UI - maybe there is some other field you can use?
    – SPArcheon
    Commented Dec 17, 2012 at 16:10

2 Answers 2


After some experimenting based on the answer provided by C. Marius I've come to the following conclusion:

If you are using ItemUpdating:

public override void ItemUpdating(SPItemEventProperties properties)
    if (properties.ListItem != null &&
        properties.ListItem.ModerationInformation != null &&
        properties.ListItem.ModerationInformation.Status == 
            SPModerationStatusType.Pending &&
        properties.AfterProperties["vti_doclibmodstat"] != null &&
        properties.AfterProperties["vti_doclibmodstat"].ToString() ==
        // Item is about to be approved and published.

If you are using ItemUpdated:

public override void ItemUpdated(SPItemEventProperties properties)
    if (properties != null &&
        properties.ListItem != null &&
        properties.ListItem.ModerationInformation != null &&
        properties.ListItem.ModerationInformation.Status == 
            SPModerationStatusType.Approved &&
        properties.ListItem.Level == SPFileLevel.Published)
        // Item was just approved and published.

There is actually no such type of event (something there is ONLY for files - using SPFileLevel.Published by getting it from Versions property), rather use a combination of validations, such as if this is a SPCheckinType.MajorCheckIn, as well as SPModerationInformation on the actual list item via the ModerationInformation.

However you would also need to do this only after checking if the actual List has ModerationEnabled (requiring Approval) and also if Major/Minor is enabled via the EnableVersioning.

Your Answer

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

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