1

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++
  }

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

site.sharepoint.com/sites/mysite/Lists/ContactList/Attachments/1/**PhotoName1.jpg**

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

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** – Christopher Mar 18 '16 at 12:34
  • Yeah..just change variable PicName1 to PicName2 in above code. – SP Developer Mar 19 '16 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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