Forum Discussion

GSYSJobs's avatar
GSYSJobs
Copper Contributor
Jul 06, 2023
Solved

Get the preview URL in SharePoint Document library via REST API

I am making a custom web part that connects to the Documents list on SharePoint via Fetch. This is the call that I use for retrieving information:

 

/_api/web/lists/getByTitle('Documents')/items?$select=EncodedAbsUrl,*,File/Name&$expand=Folder&$expand=File

 

Right now I get mostly all the data that I need for all the items, but I just need to also have the URL that redirects you to the preview of the file

 

 

If possible, I don't want to make another fetch, So is there any item property that I could expand to get the preview URL, via REST API?

 

I checked the values of EncodedAbsUrl and ServerRedirectedEmbedUrl, but these are not exactly the preview URL that I have in mind.

I've seen a similar question to mine, even tho I don't need the same thing I've also tried expanding the fetch to recieve more data of vti_x005f but still, I couldn't find the preview URL

 

Similar Question 

 

With this one:

 

/_api/web/lists/getByTitle('Documents')/items?$select=EncodedAbsUrl,*,File/Name/Properties/vti_x005f_shortcuturl&$expand=Folder&$expand=File&$expand=Properties

 

Thank you in advance,

  • Solved!
    Using the next URL we can retrieve the value "FileRef"
    /_api/web/lists/getbytitle('Documents')/items?$select=*,FileLeafRef,FileRef
    With these what I've made is

    https://contoso.sharepoint.com/sites/<<Name of your Site>>/Shared%20Documents/Forms/AllItems.aspx?id="+encodeURIComponent(file.FileRef.trim())+"&parent=/sites/<<fileName>>/Shared%20Documents

1 Reply

  • GSYSJobs's avatar
    GSYSJobs
    Copper Contributor
    Solved!
    Using the next URL we can retrieve the value "FileRef"
    /_api/web/lists/getbytitle('Documents')/items?$select=*,FileLeafRef,FileRef
    With these what I've made is

    https://contoso.sharepoint.com/sites/<<Name of your Site>>/Shared%20Documents/Forms/AllItems.aspx?id="+encodeURIComponent(file.FileRef.trim())+"&parent=/sites/<<fileName>>/Shared%20Documents

Resources