سؤال

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);}
هل كانت مفيدة؟

المحلول 2

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.

نصائح أخرى

you could use returnValue.newFileUrl in the callback function

function OpenModalDialogOrganoAdministracion() {
  var options = {
             url: 'http://servidor/libreria',
             title: 'Añadir Documento',
             allowMaximize: false,
             showClose: false,
             width: 800,
             height: 600,
             dialogReturnValueCallback: function(dialogResult,returnValue){
                        if(dialogResult==SP.UI.DialogResult.OK) {
                          alert(returnValue.newFileUrl); 
                        }
             }
            };
SP.UI.ModalDialog.showModalDialog(options);
}

It's not really what you're asking, but I use another way to upload/create a file into a Sharepoint document library: SharepointPlus - createFile()

That way it's the user that defines the name of the file. So you already know the name :-) You may need to first check the name doesn't exist already in the library before uploading it.

I hope that helps...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top