I was using JSLink to change the display of a documents webpart. I was retrieving the document icon url set by Sharepoint for a document library item like this:
(it can be shortcut icon (DOCLINK.GIF), or document type icon (ictxt.gif, ichtm.gif, icdoc.gif, etc.) -> i.e. not the File type document, since shortcuts are aspx files, but are not the same icon as a standard aspx file: it recognizes it's a shortcut (="Link to document" type) )
itemHtml:function (ctx) {
//...
var iconURL = ctx.imagesPath+ctx.CurrentItem["HTML_x0020_File_x0020_Type.File_x0020_Type.mapico"];
//...
}
It is working fine.
Now i'm trying to get that same icon with CSOM and caml query, for easier implementation (JSLink is quite a pain to do)
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='int'>0</Value></Eq></Where></Query></View>");
collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);
clientContext.executeQueryAsync(function () {
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
//...
var icon = oListItem.get_item('???');
//...
}
}, function(){
alert('error');
});
Do you know a way to get the icon set by SP for each item?
Many thanks!
ctx.executeQueryAsync()
: First fetch all items and store the relevant values in an array (e.g. title, filename, ...). Within your firstOnSuccess
function you iterate over the array and store the icon like this:results[i]["docicon"] = web.mapToIcon(results[i]["filename"], '', SP.Utilities.IconSize.Size16);
When you've iterated over the complete array callctx.executeQueryAsync()
a second time. Wihtin the secondOnSuccess
function you should be able to access the icon image name atresults[i]["docicon"]
.