Sunday, April 19, 2009

Dataview Webpart displaying multiple file icons

Scenario:
Let me try, if I can explain this requirement. We had a document library and users had files in two different format XLS and PDF with same name.

Now they wanted to display one line for each file name with two icons representing these two files ( one XLS and another PDF ). Yes , right client is client.

Solution:
DataView Webpart is one famous weapon for these tough situations and yes SPD also.
We used a DataView webpart and added following extra header and data column.

multiple
XSL Column Header:

<!--DocIcon-->
<TH nowrap="" scope="col" class="ms-vh2">
<xsl:call-template name="dvt.headerfield" ddwrt:atomic="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
<xsl:with-param name="fieldname">@DocIcon</xsl:with-param>
<xsl:with-param name="fieldtitle">CSV</xsl:with-param>
<xsl:with-param name="displayname">CSV</xsl:with-param>
<xsl:with-param name="sortable">0</xsl:with-param>
<xsl:with-param name="fieldtype">Text</xsl:with-param>
</xsl:call-template>
</TH>
XSLT Column Data:
<!--DocIcon-->
<TD Class="{$IDAG3PVE}">
<xsl:variable name="PDFPATH" select="concat(substring-before(@FileRef,'xls'),'pdf')"></xsl:variable>
<xsl:variable name="FieldIDA1QZMH">
<xsl:choose>
<xsl:when test="@IsCheckedoutToLocal=''"></xsl:when>
<xsl:otherwise><A HREF="{ddwrt:URLLookup('', 'IsCheckedoutToLocal', string(@ID))}"><xsl:value-of select="@IsCheckedoutToLocal" /></A></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="@FSObjType='1'">
<xsl:choose>
<xsl:when test="ddwrt:GetVar('RecursiveView')='1'"><IMG BORDER="0" alt="Folder: {@FileLeafRef}" SRC="/_layouts/images/folder.gif" /></xsl:when>
<xsl:otherwise>
<xsl:variable name="SetVarIDAOMZMH"><xsl:value-of select="$PagePath" />?RootFolder=<xsl:value-of select="@FileRef" />&FolderCTID=<xsl:value-of select="@ContentTypeId" /></xsl:variable>
<xsl:value-of select="ddwrt:SetVar('UnencodedFilterLink', string($SetVarIDAOMZMH))" />
<A TABINDEX="-1" HREF="{ddwrt:GetVar('UnencodedFilterLink')}" onclick="javascript:EnterFolder('{ddwrt:GetVar('UnencodedFilterLink')}');javascript:return false;"><IMG BORDER="0" alt="Folder: {@FileLeafRef}" title="Folder: {@FileLeafRef}" SRC="/_layouts/images/folder.gif" /></A>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise><A TABINDEX="-1" HREF="{$PDFPATH}" onclick="return DispEx(this,event,'','','','','{ddwrt:ListProperty("DefaultItemOpen")}','{ddwrt:MapToControl("", string())}','{@HTML_x0020_File_x0020_Type}','','{ddwrt:GetUserID('CheckoutUser')}','{$Userid}','{ddwrt:ListProperty("ForceCheckout")}','{$FieldIDA1QZMH}','{ddwrt:CurrentRights()}')">
<xsl:choose>
<xsl:when test="@CheckoutUser=''"><IMG BORDER="0" ALT="{@Title}" title="{@Title}" SRC="/_layouts/images/XLS16.gif" /></xsl:when>
<xsl:otherwise><IMG BORDER="0" ALT="{@Title}" title="{@Title}" SRC="/_layouts/images/XLS16.gif" /></xsl:otherwise>
</xsl:choose>
</A></xsl:otherwise>
</xsl:choose>
</TD>
Issues:
1. Works only for only Document Library, can be enhanced for Link list also.
2. The way we wrote the XSLT transformation variable PDFFILEPATH. Users need to upload only XLS file and he will get link for PDF. ( Simple file name replacement function ).
3. This solution doesn't really check if that PDF file exist or not.

0 comments: