Reputation: 43
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);}
Upvotes: 1
Views: 2382
Reputation: 21
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);
}
Upvotes: 2
Reputation: 43
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.
Upvotes: 1
Reputation: 3927
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...
Upvotes: 0