I am trying to retrieve the names of two attached files that a single item may contain in a list

I'm not sure how this function works, but here is what I have so far

var PicName1 = '';
var PicName2 = '';
  for (var file in attachmentFiles) {
    if (attachmentFiles.itemAt(i)) {
      PicName1 = attachmentFiles.itemAt[i].get_name(0);
      PicName2 = attachmentFiles.itemAt[i].get_name(1);

I went out on a limb with get_name(0) and get_name(1) in hoping that it would find the name of the first and second file in that item. However, both of them return the name of the final attachment in the item (this is the same result as get_name()).

The get_name() function returns the following stared value in a URL that points to a list item


Is there a way I can extract the name of each file like this?

1 Answer 1


Try this,

var pictureName = PicName1.substring(PicName1.lastIndexOf('/') + 1);

In your case it will return "PhotoName1.jpg"

Look this thread

  • Thanks so much for the reply! Will this method also work for extracting PhotoName2.jpg? Of the same item. ie: site.sharepoint.com/sites/mysite/Lists/ContactList/Attachments/1/**PhotoName2.jpg** Mar 18, 2016 at 12:34
  • Yeah..just change variable PicName1 to PicName2 in above code. Mar 19, 2016 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.