Tuesday, January 05, 2010

Identify Publish a Major Version

For some strange reason SharePoint doesn't raise an ItemCheckingIn or ItemCheckedIn event when documents are published in new major versions, unless you do a Checkin and select major version in the same operation.

How can you identify a "Publish a Major Version" with other events? I did some googling and experiments and found out that using BeforeProperties and AfterProperties in the ItemUpdating handler might do the job. Similar posts can be found here, but I didn't get the same result.

int iBefore, iAfter;
iBefore = int.Parse(properties.BeforePropeties["vti_level"]);
iAfter = int.Parse(properties.AfterPropeties["vti_level"]);

Using the value of iBefore and iAfter I was able to identify the following events:
CheckIn Minor Version
CheckIn Major Version
Publish a Major Version

So if (iBefore == iAfter) you a facing a "Publish a Major Version" event.


Anonymous said...

You saved my day. Thanks

Bruce said...

hmm this doesnt quite work fully..updating the title on an item triggers a 'major publish'!

Morten Marquard said...

Bruce - this might depend on the version control settings and publishing settings.

Jan said...

So if (iBefore == iAfter) you a facing a "Publish a Major Version" event.
Or it could be an minor version check-in. Publishing would be "iBefore == iAfter == 2" going by your table.
Very useful analysis, I have just put it to use here.