Document Icon in CQWP

Description

This article will show you how to display icon in Content Query Web Part (CQWP).

Requirement:-

In several requirements we use existing CQWP and modify XSLT to make required view.
In one of requirement i asked to display icon of uploaded document.
I found the very simple solution for which detail is described further in blog.

The Code:

As i explained above; here also we will write xslt template to mitigate this requirement.
Steps.
1. Export existing web part.
2. Add DocIcon in view fields. Which would look like

1
<property name="CommonViewFields" type="string">DocIcon, Lookup;</property">

3. Then again import this web part into site.
4. Go style library and edit item.xslt
5. Add below xslt template (Mainly look at highlighted code) and you refresh your page. You should see doc icon.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<xsl:template name="RecentDcoument" match="Row[@Style='RecentDcoument']" mode="itemstyle">
	<xsl:variable name="SafeLinkUrl">
	<xsl:call-template name="OuterTemplate.GetSafeLink">
	<xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
	</xsl:call-template>
	</xsl:variable>
	<div id="linkitem" class="item" style="vertical-align:middle;">
	<div style="float:left;">
	<IMG BORDER="0" ALT="{@FileLeafRef}" title="{@FileLeafRef}" 
	      SRC="/_layouts/images/{ddwrt:MapToIcon(string(@DocIcon),string(@DocIcon))}" />
	</div>
	<div>
	<xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
	<a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}" 
	        style="padding-left:5px;">
	<xsl:value-of select="ddwrt:UrlBaseName(string($SafeLinkUrl))" />
	</a>
	</div>
	</div>
</xsl:template>

Hope it helps!

Thanks!
Avinash

calendarMarch 12, 2012 · cardInfoyen · commentsNo Comments
tagTags: , , , ,  · Posted in: CQWP, MOSS, SharePoint

Leave a Reply

Spam Protection: , required

myworldmaps infoyen