Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to add an 'Upload Documents' button onto onto the welcome page of a Document Set. I found the following code at: http://sharepointaddict.blogspot.com.au/2012/10/add-upload-document-button-to.html

However when I run it, the modal window that pops up gives a 'file Not Found' error with the modal url of http://intranet/functions/it/testbed/Contract%20Review/Forms/_layouts/Upload.aspx?List=undefined&RootFolder=undefined&IsDlg=1&IsDlg=1

I added the code to a content editor webpart on the welcome page design.

Any ideas?

    <script src="/functions/it/testbed/SiteAssets/jquery-1.10.0.min.js" type="text/javascript"></script><script src="/functions/it/testbed/Contract%20Review/Forms/_layouts/SP.UI.Dialog.js" type="text/javascript"></script><script src="/functions/it/testbed/Contract%20Review/Forms/_layouts/SP.UI.Dialog.debug.js" type="text/javascript"></script><script type="text/javascript">



 //Using this to control when my script executes - don't want the script to load //on form load but on form click. I call this function in my runCode function  
 //below and then call the runCode function in my Upload Document's onclick event  
 $(document).ready(function(){  
 SP.SOD.executeOrDelayUntilScriptLoaded(initialize,'SP.js');  
 SP.SOD.executeOrDelayUntilScriptLoaded(test,'SP.js');  
  });  
 //takes the querystring from the first query string parameter in the Document Set //url to the last then splits it into an array using the ampersand (&) as the delimeter  
 function getUrlVars() {  
   var vars = {};  
   var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {  
     vars[key] = value;  
   });  
   return vars;  
 }  
 //Using the function to get the values we will use to obtain the url of the //upload document function dynamically  
 var listID = getUrlVars()["List"];
 var rootFolder = getUrlVars()["RootFolder"];  
 //This function opens up the form in modal dialog mode  
 function openDiaForm()  
 {    
   var diaOptions = SP.UI.$create_DialogOptions();    
   diaOptions.url = 'http://intranet/functions/it/testbed/Contract%20Review/Forms/_layouts/Upload.aspx?List='+ listID + '&RootFolder=' + rootFolder + '&IsDlg=1';    
   diaOptions.width = 800;    
   diaOptions.height = 600;    
   diaOptions.title = "Upload Document Form";  
     diaOptions.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);  
   SP.UI.ModalDialog.showModalDialog(diaOptions);  
 }  
 //The function refreshes the content of the Document Set Welcome Page after the Upload Document modal dialog box has been closed  
 function CloseCallback(result, target) {  
     location.reload(true);  
   }  
 function runCode() {  
   var x = ExecuteOrDelayUntilScriptLoaded(openDiaForm, "sp.js");  
 }  
  </script><div class="ms-uploadbtnlink"><button onclick="runCode();" type="button" value="Run Code">&#160;<span>Upload Document</span></button> </div>
share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

The values for the ListID and RootFolder are returning as null when trying to execute the script .

When i hardcoded the below part specifying the URL of site and List Id.. I was able to get the script working.

Hence the problem here is fetching the ListId and RootFolder in the Script

diaOptions.url = '[Your Site URL]/_layouts/Upload.aspx?List=[Your List ID]&IsDlg=1';
share|improve this answer
add comment

Move these two lines

var listID = getUrlVars()["List"];
var rootFolder = getUrlVars()["RootFolder"];

inside the function openDiaForm()

They seem to be undefined as it is now!

Also remove Contract%20Review/Forms/ part of the URL, it should be URLTOWEB/_layouts/Upload.aspx...

so for you:

http://intranet/functions/it/testbed/_layouts/Upload.aspx?List='+ listID + '&RootFolder=' + rootFolder
share|improve this answer
    
So that helped, but I still get the same error. The URl is now: intranet/functions/it/testbed/Contract%20Review/Forms/_layouts/… –  TechVagabond May 28 '13 at 7:10
    
One other thing is that you are passing IsDlg to the method, that is not needed as you can see by the resulting url where it is featured twice –  Robert Lindgren May 28 '13 at 7:28
    
Updated answer about URL –  Robert Lindgren May 28 '13 at 7:31
    
I also had the wrong path to the upload.aspx –  TechVagabond May 28 '13 at 8:18
    
I know you did, and frankly MPArvind does not mention the URL being wrong in his answer, he just happens to write the correct url to prove the point of listID being "null" -well really undefined –  Robert Lindgren May 28 '13 at 8:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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