querying document libraries using SharePoint REST

today I needed to query a document library using the REST api. I found that simply calling _api/web/list/getbytitle(‘foo’)/items would not return me either the filename or full path.

The secret is to call FieldValuesAsText – here FileRef (the server relative path) and FileLeafRef are present. One can either call it directly

/_api/web/list/getbytitle('foo')/items(2)/FieldValuesAsText

or expand it like so

/_api/web/list/getbytitle('foo')/items?$expand=FieldValuesAsText&$select=Id,FieldValuesAsText/FileRef,FieldValuesAsText/FileLeafRef

Additionally, to get a nice Icon to display one can call

/_api/web/maptoicon(filename='filename.ext',progid='',size=0)

size can be 0 or 1 – for small or large images respectively.

The Doumentation for this can be found at SP.Web.mapToIcon and SP.ListItem.fieldValuesAsText.

Leave a Reply

Your email address will not be published. Required fields are marked *