Tuesday, 10 May 2011

jQuery to override SharePoint OOTB Upload.aspx default for "Add as a new version to existing files" checkbox

A common query from SharePoint users with versioning enabled on document libraries is to default the "Add as a new version to existing files" checkbox on the OOTB upload.aspx page to unchecked. If you google how to uncheck it by default you'll get lots of entries showing you how to simply edit the Upload.aspx file in the \TEMPLATE\LAYOUTS\ folder in the 12/14 hive. This works fine of course if you don't care about tomorrow and having a supported/upgradeable SharePoint installation.

If you do there is a better way as described by Per Jakobsen here.
Using the AdditionalPageHead delegate control to inject javascript to the page through a feature not only gives you a supportable system but allows you to switch the default to checked or not checked by activating or deactivating the feature.

I tried a variation of this on a SharePoint 2007 installation and it worked fine, after an upgrade to 2010 it stopped working however. Having spent five minutes trying to debug the issue I decided it would be swifter to just change it to use jQuery's $(document).ready function rather than solve the specific problem. There seems to be others having weird things going on with _spBodyOnLoadFunctionNames.push in 2010, so this is probably a quicker fix (at least if you've already got jQuery available on the page). If you don't you could add a reference to it in the DefaultUploadOverwriteOff.ascx user control.

The change to Jakobsen's javascript is simple, just replace the function DefaultUploadOverwriteOff() with this:
$(document).ready(function() {
    if (document.title == "Upload Document") {

and remove the last line: _spBodyOnLoadFunctionNames.push('DefaultUploadOverwriteOff');

This now works fine on both 2007 and 2010.


  1. Hi Vegard,

    Thanks for your solution.

    What if I just want to disable versioning for a single doc. library only (the uploaded file is a Record not to be changed with a new version)? But I need versioning in the same doc. library for all the Meta Data changes!

    OOTB SharePoint 2010 is not really helpful to make above happen.


    1. Hi Peter

      Don't think you can have separate versions for metadata and document in 2010. You might get closer with 2013 as it stores deltas of file changes rather than a new copy when a change occurs.


  2. Any chance you could compile the 2010 WSP file? I don't have the appropriate tools to do so myself.