Tuesday, 24 December 2013

Programmatically Hiding the "Overwrite existing files" checkbox for a single library

Hi All,
Last week i got a challenge for hiding the "Overwrite existing files" checkbox for a particular library.
First i thought it would be very easy , because my option was like adding a simple javascript to hide for that library.
I opened SharePoint Designer and tried adding javascript to that. It was not reflecting.. :(:(

On digging deep, I came to know that Upload.aspx is an application page and it is coming from the Layouts folder.
Ok finally i thought i found out the solution and tried changing the Upload.aspx page in the layouts folder. But the checkbox got hidden on all the pages..

Again i have to give a check on that so that it gets reflected for only one library. Finally i pointed out the List GUID in the URL of the page.

Then i tried and found 2 solutions for hiding checkbox for a single library.

Solution 1) Use this script in your master page

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready( function () {
        if (location.href.indexOf('0ABCE757-34A6-409D-A230-72382C924651') >= 0)
 // you must need to change GUID of your lib above
       {
            $("label:contains('Add as a new version to existing files')").prev('input').hide();
            $("label:contains('Add as a new version to existing files')").hide();
            $("a:contains('Upload Multiple Files...')").hide();
        }
    });
</script>

For easily finding the GUID of a library u can refer my post here


The second solution I will share on my next post. C ya!!!!


No comments:

Post a Comment