Hide Add as a new version checkbox on upload in SharePoint Online

I was asked to find a solution to hide the checkbox and label (Add as a new version to existing files) you can see when uploading a document in SharePoint Online. If the customer doesn’t want users to accidentally overwrite documents in a library, this script will add a bit of awareness. The below JavaScript will make it a bit harder for them to accidentally add a new version to existing files but this will not prevent overwriting completely!

image

This solution will add a bit of code to the Master Page where you can create a custom Master Page for this. There is a lot of commotion around creating custom Master Pages or even editing the default and the following blog explains a bit about this: http://blog.sharepointexperience.com/2015/01/to-brand-or-not-to-brand/ . I wasn’t able to hide this successfully using for example a script editor web part so please let me know if you can do this Smile

Manual to hide Add as a new version checkbox

You can copy and paste the following bit of code to the Master Page above the </head> entry.

<script src="<a href="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&quot;">https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"</a> type="text/javascript"></script>
<script type="text/javascript">
$(document).ready( function () {
//you can specify a document library guid if you only need to change this for a specific library
if (location.href.indexOf('A9A5E8AC-3FC6-4279-AE8D-A7C8B9688209') >= 0)
{
//hide the labels from upload.aspx
$("label:contains('Overwrite existing files')").prev('input').hide();
$("label:contains('Overwrite existing files')").hide();
//hide the checkbox from upload.aspx
$("a:contains('Upload Multiple Files...')").hide();
//set the checkbox as unchecked
$("input[type='checkbox']").attr('checked',false);
}
});
</script>

You can find the library GUID at the  library settings page:

image

result

The next time you upload a document the upoad.aspx page will look like the below:

image

This checkbox is also hidden when you link to this document library using a web part. This does not prevent users from overwriting files but adds a extra layer of awareness. The checkbox is always checked and this script also unchecks it. The standard question pops-up when a user tries to add a document with the same name to the library.

gebruikerskeuze

The user can select ‘Replace it’ or ‘Don’t Upload’

Leave a Reply

Your email address will not be published. Required fields are marked *