Manipulate upload link in document library

I got this request from JGilmore:

Anyone know how to change the URL of the ‘Upload’ button as well as the links under its dropdown? I would like to have the user directed to a custom upload page with ‘Overwrite existing files’ unchecked by default.

Thanks in advance.


Here is one possible approach

Add this code in a CEWP below the list view to override the default links:
[javascript]
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">

// Manipulate direct click on upload button
$("*[id$=’_UploadMenu’]").parents(‘td:first’).removeAttr(‘onclick’).click(function(){
redirectUpload(false);
});

// Manipulate "Upload Document"
$("*[id$=’_Upload’]").attr(‘onMenuClick’,’redirectUpload(false)’);

// Manipulate "Upload Multiple Documents"
$("*[id$=’_MultipleUpload’]").attr(‘onMenuClick’,’redirectUpload(true)’);

function redirectUpload(multi){
// Set your new upload destination (custom upload page)
// ctx.listName is provided by SharePoint
if(multi){
window.location=’/test/English/MyCustomUploadPage.aspx?List=’+ctx.listName+"&MultipleUpload=1";
}else{
window.location=’/test/English/MyCustomUploadPage.aspx?List=’+ctx.listName;
}
}
</script>

[/javascript]

Change the new upload location in the function “redirectUpload”. Also edit the source of the jQuery script if you prefer to use a local copy.

Ask if anything is unclear.

Alexander

11 thoughts on “Manipulate upload link in document library”

  1. Hi, I have multiple view in doc lib. I put the codes in cewp in AllItems.aspx view however when I switch to other view the script is not working and redirect to the original upload.aspx.
    Is there a way when you are in the document lib regardless of what view you select it will redirect to this custom upload page?
    Please advice. Thanks!

    1. Hi,
      This kind of client side code has to be placed in each and every page. To overcome this you would have to modify the master-page and put the scripts on the server side.

      Alexander

    2. Hi Alexander,

      What if I have multiple document library and I do not want to use the custom upload

      for e.g doclib1 = use the custom upload
      doclib2 = use the sharepoint upload
      and the rest of the sharepoint list will use the sharepoint upload

      If I edit the masterpage is this applicable to all list and redirect to custom upload or can we just hardcode which doclib will use this script in the masterpage?

      Thanks and hope for your immediate respose.

    3. Hi,
      This code is intended for client side and requires the code to be put in all views.

      The server side approach was just a lead to you, but nothing i can help with here.

      If you do this and goes “server side” i guess modifying the existing upload page is a better approach, but again – nothing i can help with.

      Alexander

    4. Thanks Alexander for the info, right now I will just stick with this solution client side.

      Just a follow up question how can I can capture the full URL of the previous page before I click this upload button? currently it only display the {listid}
      my requirement is to capture the full url including the rootfolder>subfolders, content types ctid etc..

    5. Thanks Alexander for the info, right now I will just stick with this solution client side.

      Just a follow up question how can I can capture the full URL of the previous page before I click this upload button? currently it only display the {listid}
      What I need is to capture the full url including the rootfolder>subfolders, content types ctid etc.. via query string and parse it based on my reqmnts.

  2. This has been very helpful, thanks! I am curious if there is a way to check the size of a file before it can be uploaded using a CEWP. I thought I found something in the past, but am unable to find it with some decent time in google.

    Thanks for any help you can provide, lots of great stuff on your site.

  3. Pingback: mytechcrush

Leave a Reply