2

I have to display other site collection list data in root site. I am using REST API call to do that. But I am stuck while fetching 'DocIcon'. Can anyone tell me how can I get it?

Here is my code sample:

var folderUrl = '/sites/docs/Health%20safety%20and%20environment/Emergency%20Response';
var url ="http://sharepoint.com/sites/docs/_api/Web/GetFolderByServerRelativeUrl('" + folderUrl + "')?$expand=Folders,Files";

$.getJSON(url,function(data,status,xhr){

for(var i = 0; i < data.Files.length;i++){
        $('<tr>').append(
        $('<td>').text(data.Files[i].DocIcon),
        $('<td>').text(data.Files[i].Name),
        $('<td>').text(data.Files[i].TimeLastModified.substring(0, 10))).appendTo('#records_table');
    }
});
4

The "DocIcon" property will not get you the icon itself but the file extension.

You can use mapToIcon method from the SPWeb object in JavaScript to get the image url.

Example : http://onlinecoder.blogspot.ca/2014/03/get-oob-document-type-icon-using.html

  • I am not able to get office files icons – love thakker Jul 9 '15 at 9:16
  • Do you get an error ? – JayHell Jul 9 '15 at 13:07
  • No its blank image. But I found a work around. I checked if '.gif' icon exist or not. If it does not exist I check if '.png' icon exist. If both are missing then I display general file icon else which ever is exist. – love thakker Jul 10 '15 at 6:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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