16

Interesting dilemma here maybe some can weigh in on. I have a requirement to disable the "overwrite existing files" checkbox when uploading a single or multiple documents to a document library. The initial request was to hide the control completely, although I could probably see simply disabling the control.

As the document library points to the _layouts upload.aspx page, does anyone have some input on a workaround for this?

9 Answers 9

8

One method I've used to customize the upload page is to take a copy of upload.aspx and rename it to something like upload2.aspx. Keep it in the /layouts folder (or subfolder of) since it won't like being anywhere else.

Once you have the copy, you can make your modifications as you like.

The last step is to tell the upload menu items on the document library toolbars to point to the new upload page. You can do this with some jQuery, for example

$("ie\\:menuitem[text='Upload Document']").each(function(){

   $(this).attr('onMenuClick', $(this).attr('onMenuClick')
          .replace('Upload.aspx', 'Upload2.aspx'));
 });
5
  • Thanks for all of the feedback; the crux of the issue is that we're on a corporate server and don't have access to the _layouts folder. Yet another case where there's no simple solution; even getting them to duplicate the uploads.aspx file for me is like pulling teeth (the "but the change affects everyone" argument from people that don't understand the platform).
    – webdes03
    Commented Apr 6, 2010 at 15:01
  • @Paul: I've never seen the `ie\` syntax before and it looks quite interesting. What does this mean?
    – Alex Angas
    Commented Apr 7, 2010 at 7:27
  • 4
    @Alex: Can I assume a little knowledge of jQuery? So SharePoint's menu infrastructure generally uses the tags <menu><ie:menuitem>. The $("ie\\:menuitem") above is basically 'jQuery selector syntax' which will select each <ie:menuitem> tag with a text attribute of 'Upload Document'.
    – Paul Lucas
    Commented Apr 7, 2010 at 14:37
  • @Paul: So the double backslash is essentially an escape character for the colon?
    – Alex Angas
    Commented Apr 8, 2010 at 7:43
  • That's correct! :-)
    – Paul Lucas
    Commented Apr 8, 2010 at 21:45
6

I've been asked to do this, too, and there's no really good answer that I've come up with. If you hack the _layouts/upload.aspx page, it'll take effect throughout the Site Collection(s) on that WFE. (And you will no longer be in a "supported state", and an upgrade will clobber it, and hair will grow out of your palms.)

You can, however, create a customized upload.aspx for a specific list by cloning the page and changing the New Document Form in Supporting Files for that list.

1
  • Also any changes you want to make in the LAYOUTS directory must be replicated on each web front end identically. Or hair will grow out of your palms :)
    – James Love
    Commented Feb 1, 2012 at 20:06
3

As a non-javascript alternative you could have a look at this article: Customize the SharePoint Upload Page by Russel Gove.
It is also available as installable package, see http://spcustomupload.codeplex.com.
You might need to simplify it a bit to meet your requirements.
Add for instance

this.UploadMultipleLink.Visible = false; 

to the Onload methode of your custom Upload application page which inherits from UploadPage class.
Hint: Instead of renaming a copy of Upload.aspx from the Layouts - folder (cf. article), add that copy to a custom subfolder of Layouts - folder without renaming it.

1

Step 1: Download and import jquery.min.js into SPD Site Assets

Step 2: Create HideUpload.js and import it on SPD Site Assets

//HideUpload.js
//Control id captured by browsing (e.g. Upload.aspx) page from SPD

jQuery(document).ready(function ($) {

//alert('hiiiiiiii');

//var MultipleUpload = document.getElementById("ctl00_PlaceHolderMain_UploadDocumentSection_ctl03_UploadMultipleLink");
//if( MultipleUpload != null)
//{
//  alert('multiple upload inside');
//  MultipleUpload.style.display= "none";
//}
//ctl00_PlaceHolderMain_ctl04_ctl02_uploadLocation

var DestinationFolder = document.getElementById("ctl00_PlaceHolderMain_ctl04_ctl02_uploadLocation");
if( DestinationFolder != null)
{

//  alert('DestinationFolder  inside');
//  DestinationFolder.style.display= "none";
        DestinationFolder.disabled= "true";
}

var ChooseFolder = document.getElementById("ctl00_PlaceHolderMain_ctl04_ctl02_selectTargetButton");
if( ChooseFolder!= null)
{

//  alert('ChooseFolder inside');
//  DestinationFolder.style.display= "none";
        ChooseFolder.disabled= "true";
}

    //let's call the method that hides the link and pass
    //in the GUID for our Document Library we want to hide
    //the link on
    HideUploadLink("{FCC65F1A-9D9B-4AF0-8B5C-A16B2A11050B}");
});

Step 3: Checkout the used master page and paste the following just before </head> tag.

<script type="text/javascript" src="../../SiteAssets/jquery.min.js"></script>
<script type="text/javascript" src="../../SiteAssets/HideUplaod.js"></script>
0

Back in the WSS 2 days, couldn't you copy the contents of the LAYOUTS directory to another directory (LAYOUTS_CUSTOM). Then, in IIS, change the path of the layouts virtual directory. IIRC, this was the "least bad" unsupported state since future updates wouldn't clobber your changes and you could merge them afterwards.

1
  • Making changes like these is in IIS now unsupported since WSS3.
    – James Love
    Commented Feb 1, 2012 at 20:04
0

You can create an Event Receiver that checks if a file already exists and cancels the operation if someone wants to overwrite an existing file.

Alternatively, use the free SharePoint Infuser to inject some JavaScript that checks if the current page is upload.aspx and then remove the check box.

0

When I am putting below javascript in content editor web part to change upload.aspx url, it will remove whole toolbar from the AllItems.aspx page, can you please let me know what should I need to add below to replacing upload.aspx URL?

$("ie\:menuitem[text='Upload Document']").each(function(){

$(this).attr('onMenuClick', $(this).attr('onMenuClick') .replace('Upload.aspx', 'Upload2.aspx')); });

Thanks, Sanket

1
  • Sanket, That will not remove the entire toolbar, it will only change the URL behind the Upload Document button. Mike
    – webdes03
    Commented Aug 31, 2010 at 19:16
0

Maybe you will find my solution somehow useful - Custom upload form for document library in SharePoint 2010 - programmatic approach. It's a full programmatic server side solution, it does not require any javascript tricks, it can be applied selectively to specific Document Libraries based on custom list templates (no need to change the default behaviour on entire WFE) and it is quite simple.

On stackoverflow someone posted similar question - How do I change the upload page for a particular document library in SharePoint?

0

Create a js file with below code and refer it in master page:

$(document).ready(function () {
   var d = document.getElementById("ctl00_PlaceHolderMain_ctl04");
   d.style.display = "none"; 
});

This will also hide the "Send Alerts To" portion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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