Search code examples
jquerysharepointfile-uploadsharepoint-clientobject

Return file URL from modal Dialog containing upload form


How do you return the URL of a file after it has been uploaded to a document library in SharePoint, using the default upload page? Returning the text from the "inputFile" textbox from the upload.aspx page would also work, but I can't figure out how to do that because it's loaded inside a modal dialog.

function uploadPicture(){
var currentUserDispName ='myname';
var options = {
    url: '/test/_layouts/15/Upload.aspx?List=6c7bc1b3%2D1b7f%2D466b%2Da0f5%2Dac15dc334ff7& RootFolder=/test/mydocs/' +      currentUserDispName + "&IsDlg=1",
    width: 450,
    height: 230,
    title: 'Upload a Picture',
    dialogReturnValueCallback: function(result, returnValue) {

    if (result == SP.UI.DialogResult.OK) {
          //get File URL
    } 
    else {                     
    //else
   }
    }; SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);}

Solution

  • What I ended up doing to get the file name was using SPquery. I just made a query to retrieve all items and ordered them using last modified field, and setting the rowlimit to 1. Once I did that, I can find the serverRelative URL of the file.