How to get file name from Sharepoint Asset Library

2019-04-12 03:32发布

问题:

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

回答1:

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  


回答2:

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