1

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 ?

  • see my edited answer – ateet Sep 24 '14 at 4:15
1

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.

  • I changed "if (document.title.indexOf("Upload Document") > -1)" inside your code to " if (document.title= "Upload a document" )" and it worked well.... – john Gu Oct 1 '14 at 15:10
0

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');
  • i tried your code but it did not work, can you check my edit to the original question? – john Gu Sep 23 '14 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.