Generate thumbnail of a document stored in SharePoint from its URL

In a previous article, we have seen how to generate a document thumbnail from its metadata (siteId, webId, uniqueId, docId…) retrieved from the search engine.

With these metadata, you just have to build and call an URL such as the following :<GUID>&guidSite=<GUID>&guidWeb=<GUID>&docid=<Int>&metadatatoken=<String>

Although easy to implement, this solution is not convenient every time, especially when you don’t use the search engine to retrieve data.

For example, when you use the Video REST API or the SharePoint REST API to manipulate list items, you don’t retrieve some of the required properties to generate the preview as described in our previous article.

One solution should be to query the search engine for the associated file to retrieve required metadata, then build and call the URL to generate the preview. This solution works very well but it’s pretty inefficient because you have to make 2 requests for each thumbnail.

A better solution based on the same HTTP Handler

Last week, I was working on different things around Office 365 and I discovered a better solution based on the same HTTP Handler.

It’s possible, rather than passing many parameters (siteId, webId, docId…), to pass only one parameter called ‘path’.

This parameter expects a value equal to the URL of the document/file for which you want to generate a thumbnail. To generate a preview, the URL should look like this :

In the sample above which generates a thumbnail for a video stored in an Office 365 video channel), you just have to encode the path of the file, and add it to the querystring for the ‘path‘ parameter.

I have tested with many file types (Word, Excel, PowerPoint, MP4…), stored in different containers (document libraries, video channels…) and it works for each of them.

For information, this solution is used by Delve to generate thumbnails for video files stored in Office 365 Video 😉

Delve - HomePage

14 thoughts on “Generate thumbnail of a document stored in SharePoint from its URL

  1. Pingback: How to know what file types are supported to generate previews on Office 365 ? | Beecome Digital

  2. Pingback: CSOM GetImagePreviewUrl Parameters | Question and Answer

  3. Murthy VVR

    is this still working? I’m getting 400 bad request, when I tried for a document which is in a Document Library.


  4. Zibba

    I’m getting 404 when entering the below url on browser (replaced with actual) :

    [video src="" /]


  5. Stanley Raj (@rstanleyraj)

    This is great!
    I have a PowerPoint template library. Want to display the preview in Powerpoint 2016 taskpane. So that users can search and insert slides. is it possible?
    Though I am able to get the preview in the browser as you mentioned in the article, I am not able to bind the image to a image control.

    Liked by 1 person

  6. infotectures

    Is there any documentation about all the &parameters that can be used with getpreview.ashx ? I can’t find anything…


  7. Chaitra

    It does not give a preview image for excel and .txt files. Any idea on how to get preview for .xlsx and .txt files?



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.