Question

I have a web part that displays documents and the icon based on their extension (for example Word document displays Word logo based on .docx). I am building a url to display the image

extension = "docx"
var iconLocation = hostUrl + "/_layouts/15/image/ic" + extension + ".png";

I have found through researching this topic that txt extensions need to end with .gif instead of .png. Is there a way to know for sure which icons are supported? I ran into an issue where displaying .png files didn't show a valid image but I am unable to find some sort of documentation that would tell me which files will be handled and how (.png or .gif ending, possible others?)

Was it helpful?

Solution

Below are the list icons for different files. This has been extracted from On-Premises server. But these are being used same for SharePoint online site also.

You can see a list of your file extensions and support icon images with extension.

enter image description here enter image description here

OTHER TIPS

This is the code I use

function getIconUrl(extension, isLarge){

    var filename;

    extension = extension.toLowerCase();

    switch(extension){
        case 'pptx':
        case 'ppt':
        case 'docx':
        case 'doc':
        case 'xlsx':
        case 'xls':
        case 'pdf':
            filename='ic'+extension+'.png';
        break;

        case 'html':
        case 'htm':
            filename='ichtm.gif';
        break;

        case 'zip':
        case 'aspx':
        case 'asp':
            filename='ic'+extension+'.gif';
        break;

        default:
            filename='icgen.gif';

    }

    return '/_layouts/images/'+((isLarge) ? "lg_" : "")+filename;
}

I guess we don't have txt files, but this should help you work it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top