How to uncheck “Add as a new version to existing files” inside the “Add a document” dialog

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/116122

  •  29-09-2020
  •  | 
  •  

Question

I am working on a publishing site collection using the enterprise wiki template. Currently when users want to insert an image inside the rich text editor, they will be prompted with the following:-

enter image description here

And if the user insert a picture that already exists then it will replace the existing one, which might cause the picture to be displayed inside a Wiki page which it does not belong to !!

So is there a way to do any of the following:-

  • Give the new picture a unique auto generated name?
  • To un-check the “Add as a new version to existing files” by default?
  • Or to always prevent replacing images, as this can cause many conflicts !!

i tried updating the Upload.aspx , by changing the

 <asp:CheckBox id="OverwriteSingle" Checked="true" Text="<%$Resources:wss,upload_document_overwrite_file%>" runat="server" />

to be Checked="false" instead of Checked="true" ,, but it did not change any thing ? Can anyone adivce on this please ?

Can anyone advice ?please?

Edit i added the following to my upload.aspx :-

<SharePoint:ScriptBlock runat="server">
          $(document).ready(function() {
                _spBodyOnLoadFunctionNames.push('DefaultUploadOverwriteOff');
                $(document).ready(function () {
                    if (document.title == "Upload Document") {
                        $("input[id$='OverwriteSingle']").attr("checked", false);
                        $("input[id$='OverwriteMultiple']").attr("checked", false);
                    }
     if (document.title == "Upload Image") {
                        $("input[id$='OverwriteSingle']").attr("checked", false);
                        $("input[id$='OverwriteMultiple']").attr("checked", false);
                    }
                });
      });

but it did not uncheck the check-box , can you advice ?

Was it helpful?

Solution

I did that before, but it was for Sharepoint 2010 (see my blog post).

The code I used is the one below. It must be inserted into your masterpage, just before the </head> tag :

<script type="text/javascript">
function DefaultUploadOverwriteOff() {
  if (document.title.indexOf("Upload Document") > -1) {
    var input=document.querySelectorAll("input");
    for (var i=input.length; i--;) {
      if (input[i].id.search(/\_OverwriteSingle$|\_OverwriteMultiple$/) > -1) input[i].checked=false
    }
  }
}
_spBodyOnLoadFunctionNames.push('DefaultUploadOverwriteOff');
</script>
</head>

It's pure JavaScript, so no need for jQuery. And it must be inserted into the masterpage, so no need to have a server access.

OTHER TIPS

I think uncheking the chekbox will solve all your problem. As if this checkbox is unchecked then user uploading duplicate file will get error about same name of file. And for unchecking the chechbox, see below comments.

Writing a javascript directly on upload.aspx file present in layouts/15 folder, but this is not recommended.

So in that case you can write a custom feature having a delegate control "AdditionalPagehead" to inject javascript to make checkbox "unchecked".

>         <script>
>     _spBodyOnLoadFunctionNames.push('DefaultUploadOverwriteOff');
>     $(document).ready(function() {
>         if (document.title == "Upload Document") {
>             $("input[id$='OverwriteSingle']").attr("checked",false);
>             $("input[id$='OverwriteMultiple']").attr("checked",false);
>         }});
>       </script>

For your reference you can see below links:-

Link1

Link2

Try this code: Insert JavaScript using delegate control via feature. Don't manually apply javascript in upload page directly as this will lead to a lot of compilation issue. Follow Link2

function DefaultUploadOverwriteOff()
{
   var inputs = document.getElementsByTagName('input');
   var i=0;
   for (i=0;i<inputs.length;i++)
   {
      var input = inputs[i];
      if (input.type == 'checkbox' && (input.id.indexOf('OverwriteSingle')>-1 || input.id.indexOf('OverwriteMultiple')>-1))
        input.checked = false;
   }
}
_spBodyOnLoadFunctionNames.push('DefaultUploadOverwriteOff');
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top