Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
JavaScript
$(window).load(function () {
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', ReadListItem2);

    });

    function ReadListItem2() {
        var url = location.protocol + "//" + location.host + L_Menu_BaseUrl
        var context = new SP.ClientContext(url + '/');
        var listTitle = "Apps";
        var _List = context.get_web().get_lists().getByTitle(listTitle);
        var camlQuery = SP.CamlQuery.createAllItemsQuery();
        this.listItems = _List.getItems(camlQuery);
        context.load(listItems);
        context.executeQueryAsync(ReadListItemSucceeded2, ReadListItemFailed2);

    }

    function ReadListItemSucceeded2(sender, args) {
        var itemsString = '';
        var enumerator = listItems.getEnumerator();
        $("#appsImagesout").append("<ul>");
        while (enumerator.moveNext()) {
            var listItem = enumerator.get_current();            
            
            var _url = listItem.get_item("URL").get_url();
            fr = new FileReader();

            var _att = listItem.Attachments;

            if (_url != '' && typeof _url != 'undefined') {

                $("#appsImagesout").append("<li><a target='blank' href='" +  _url + "'><img width='50px' height='50px' src='" + _att + "' style='padding-left:10px;'/><a></li>");
          
            }
            $("#appsImagesout").append("</ul>");
        }
    }

    function ReadListItemFailed2(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }


This is my JavaScript code :

Its showing undefined. I can't get the file show in my web page. Have tried so many options. Need to get rid of this as early as possible.
Posted
Updated 17-May-17 2:26am

1 solution

function printAttachments(urls)
{
if (urls.length > 0) {

for (var i = 0; i < urls.length; i++) {
var fileName = urls[i].split('/');
var files=$("#FileAttachments").append('' + fileName[fileName.length - 1] + '
');

};
}
else {
$("#fileContainer").hide();
}
}
function getAttachmentFiles(listName, listItemId, complete) {
$().SPServices({
operation: "GetAttachmentCollection",
async: false,
listName: listName,
ID: listItemId,
completefunc: function (xData, Status) {
var attachmentFileUrls = [];
$(xData.responseXML).find("Attachment").each(function () {

var url = $(this).text();
attachmentFileUrls.push(url);




});
complete(attachmentFileUrls);

}
});
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900