Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
+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? –  SPArchaeologist Dec 17 '12 at 16:10
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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