3
votes

How can I get the file name of an image from a SharePoint 2013 Asset Library?

I am trying to write a JQuery/REST snippet to search a subset of images within the library, based on their other column values and display them. I would use FileLeafRef in case of a Document Library, but I couldn't find an equivalent field in Asset Library.

I so far tried the following, neither returns file name: https:///crm/_api/Web/Lists/GetByTitle('Publication%20List')/items?select=File/Name&expand=File https:///crm/_api/Web/Lists/GetByTitle('Publication%20List')/items?select=FileLeafRef

2

2 Answers

5
votes

There is a typo in your example, in particular $ symbol is missing for $select and $expand query options (more details).

The following rest endpoints demonstrate how to retrieve file name from Assets library:

1) Using FileLeafRef property:

/_api/web/lists/getByTitle('<list title>')/items?$select=FileLeafRef

2) Using File/Name property:

/_api/web/lists/getbytitle('<list title>')/items?$select=File/Name&$expand=File

3) Using Folder/Files property:

/_api/web/getfolderbyserverrelativeurl('<list url>')/files?$select=Name  
0
votes

I believe that yt's still FileLeafRef for an Asset Library. Any chance you could put the relevant code in your question?

Here's the rest endpoint for FileLeafRef:

/_api/web/lists/getByTitle('<list title>')/items?$select=FileLeafRef

Alternatively you could always use the File Name property:

/_api/web/lists/getByTitle('<list title>')/items?$select=File/Name&$expand=File