SharePoint Internals – Hristo Pavlov’s Blog

11 June, 2008

ForceCheckOut and how it affects development

Filed under: SharePoint — Tags: , — hristopavlov @ 7:40 am

Document libraries in SharePoint have a “Require Check Out” flag which is part of the “Visioning settings”. The flag corresponds to the SPList.ForceCheckout property in the object model. This flag is very good if you don’t want your SharePoint users to worry about checking out files. The files will be automatically checked out every time whey edit a document if this flag is turned on. However this will also affect your code if your are working with documents and metadata.

“Require Check Out” is “No”

When users upload a document it will be automatically checked in. Then they will be redirected to the EditForm.aspx and the buttons will be “OK” and “Cancel”. If they press cancel at this stage the document will appear in the document library as checked in.

In  the same time when you add a document using the SPFileCollection.Add() method, the file will be added with a checked in status.

“Require Check Out” is “Yes”

When a document is uploaded from the GUI it will be created and then will be automatically checked out by SharePoint (This is done on OnSubmit() in the Upload.aspx page). Then the user is redirected to the EditForm.aspx page and the buttons on the page will be “Check In” and “Cancel”. If the user presses cancel at this stage the document will appear in the document library as checked out (it will just keep its checked out state). If the user clicks “Check In” the document will be checked in overwriting the current checked out version and you will end up with only 1 version (which is expected).

In your code, when you call SPFileCollection.Add() method to add a document as soon as the method returns the document will have status checked out. So if you now try to call SPFile.CheckOut() to do further processing as you would if you were working with a document library that had “Require Check Out” set to false, this will throw an exception.

Also if you have an event receiver defined for ItemAdded and you run code with elevated privileges recreating the SPSite, then the document will not appear for you because it has been just added and the only existing version is not checked out to the administrator (the elevated privileges account). So in your event receiver code make sure to use the ListItem from the provided properties rather than getting a new list item from the recreated SPSite under the elevated privileges account.

1 Comment »

  1. […] ForceCheckOut and how it affects development […]

    Pingback by Links (6/12/2008) « Steve Pietrek - Everything SharePoint — 13 June, 2008 @ 2:12 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

You are commenting using your 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

Blog at

%d bloggers like this: