Last active
August 19, 2021 12:53
-
-
Save cmd64/e6b96df82d380341ad441b41d7b092be to your computer and use it in GitHub Desktop.
[JS]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
SP.SOD.executeFunc('sp.init.js', 'SP.ScriptHelpers', GetCurrentItemAttachments); | |
}); | |
function GetCurrentItemAttachments() { | |
var url = document.location.href; | |
if (url.toLowerCase().indexOf("dispform.aspx") > -1) { | |
var attachments = $('#idAttachmentsTable a'); | |
if (attachments.length > 0) { | |
var urlSplited = url.split('/'); | |
var listIndex = urlSplited.indexOf("Lists"); | |
var listName = urlSplited[listIndex + 1]; | |
$.each(attachments, function (i, v) { | |
var fileName = $(v).text(); | |
var attUrl = _spPageContextInfo.webServerRelativeUrl + "/Lists/" + listName + "/Attachments/" + SP.ScriptHelpers.getDocumentQueryPairs()["ID"] + "/" + fileName; | |
$.ajax({ | |
url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/getfilebyserverrelativeurl('" + attUrl + "')", | |
type: 'GET', | |
headers: { | |
'Accept': 'application/json;odata=nometadata' | |
}, | |
success: function (data) { | |
$(v).text(fileName + " (" + new Date(data.TimeCreated).toLocaleString("tr-TR") + ")"); | |
}, | |
error: function (jqXHR, textStatus, errorThrown) { | |
console.log('jqXHR: ' + jqXHR); | |
console.log('textStatus: ' + textStatus); | |
console.log('errorThrown: ' + errorThrown); | |
} | |
}); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment