Sharepoint : problem when we update a file during a checking in

 

logo

 

Recently, somebody asked me to add version history to word documents stored in Sharepoint. The word documents were docx files, based on the OpenXML format. This was a great opportunity to try the new OpenXML sdk 2.0 CTP (I’ve used a lot the Package & PackagePart classes in the past).

I decided to create an event handler overriding ItemCheckingIn method of the SPItemEventReceiver class and to a table in my OpenXml document (fig 1).

image

Fig 1.Overriding ItemCheckingIn and modifying the document

Then, after having associated my event handler with a document library, checking in a document generated an exception (fig 2)

version-step1-error

Fig 2.Save Conflict exception when we update a list item during a Checkingin

 

To check my code, I’ve tried the following tests (without success):

  1. I’ve commented the AddTable() function –>same error
  2. Instead of Update, I’ve tried SystemUpdate() –>same error

 

Then I decided to override the CheckedIn event instead of the Checkingin (fig 3)

image

Fig 3. Trapping the ItemCheckedIn event

 

When I checked in, I got the usual window asking to to select the version (fig 4) ; here let’s select 0.2

image

Fig 4. Version selection , selecting 0.2

 

When I clicked on the document, indeed the version history shows up (fig 5).

image

Fig 5.Version history in the word document

But when I checked the version history, I’ve noticed that the system had created an additional draft version (fig 6).

image

Fig 6. version history: an additional draft version created.

The real culprit is the call to the SPFile::SaveBinary() function (see fig 3); it seems that there is no way to bypass it ! I’ve tried several things like removing the call to SaveBinary() and calling Flush() and Close() on the stream the file was not modified.

I hope that we will find a elegant way to achieve this in Sharepoint vNext.

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s