12
Oct

Recently I have been working on an event handler for a SharePoint document library. This document event handler has 2 tasks:

1) Update 4 metadata fields with various pieces of information.

2) Update the header and footer of the document with the value of one of that metadata fields.

 

So I worked on this piece of code and eventually thought I had successfully completed it. However, it was pointed out to me that after uploading a document for the first time the version number was appearing incorrectly. a newly checked in document should have a version number of 0.1, all the documents I was checking in had a version number of 0.3. The reason for this was obvious enough. The event handler is triggered when the item is checked in. The way this piece of code works means the document must be checked out and back in for 1) the metadata update AND 2) the header / footer update. so, with the event’s own checkin and the 2 custom code checkins the document version had become 0.3.

I spent a lot of time making very large code changes in my attempts to solve this problem. In the end (after having rewritten large chunks of code with no success) a colleague pointed out a much easier way to set the correct version number. I had been checking in the document every time using:

 

SPFile.CheckIn(“Check In Document”);

 

However, I was unaware that there was another additional parameter that could be set to keep the same version number throughout the event handler:

 

SPFile.CheckIn(“Check In Document”, SPCheckInType.OverwriteCheckIn)

 

By overwriting the document version for the 2 custom code checkins the version number will not increase now until the user wants to create a new version. 

VN:F [1.9.2_1090]
Rating: 7.7/10 (3 votes cast)
VN:F [1.9.2_1090]
Rating: 0 (from 0 votes)
Stopping SharePoint checking in multiple versions of a document, 7.7 out of 10 based on 3 ratings

Comments are closed.

-->