I am trying to not have to create a different content type for a document library. Instead I was thinking if given the files in a document library I can find out which file template was used for that document.

Is there such thing? Can I query it with JavaScript/SPFX webpart?


2 Answers 2


We can use the below REST API code to read the specific file from SharePoint:

var requestUri = _spPageContextInfo.webAbsoluteUrl +
             "/_api/web/lists/getByTitle('My Documents')/items?$select=EncodedAbsUrl&$filter=Id eq 6";

var requestHeaders = {
    "accept": "application/json;odata=verbose"

    url: requestUri,
    type: 'GET',
    dataType: 'json',
    headers: requestHeaders,
    success: function (data) 
       $.each(data.d.results, function(i,result) {
            var path = result.EncodedAbsUrl;
            var fileTemplate= result.Template;


    error: function ajaxError(response) {
        alert(response.status + ' ' + response.statusText);


  • var path = result.EncodedAbsUrl; - This gives the absolute URL of the file
  • now type result.Template which will give the template name - may be the exact template attribute name will be different, then in the debug mode (F12) after result. type "Templ" - then we will get the exact attribute name.


Get documents By ID from document library using Rest API

  • Thanks, Although that does not quite answer the question, there is not such a name and you just showing how to query a document library, we need to expand the content type. I am posting a separated for the sake of clarity. Mar 25, 2020 at 18:52

For whoever is looking for the same. You can achieve by expanding the ContentType of the the file. here is the api path:


Hope it helps someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.