How to show Attachments with DataFormWebPart

If you are using DataFormWebPart and you need to add the list of attachments to the output you have to modify the XSLT to use the AttachmentsField control.

If you simply use  

 <xsl:value-of select="@Attachments"/>

the result displayed will be a boolean (Yes/No) value. If you want to display the list of attachments with corresponding links you must use AttachmentsField control as described below. This control contains the logic needed to get the attachments and render the list with links.

First of all, locate the template with name dvt_1 and add the html code to insert a new column header like in the following example:

     <xsl:template name="dvt_1">
        <xsl:variable name="dvt_StyleName">Table</xsl:variable>
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
        <table border="0" width="100%" cellpadding="2" cellspacing="0">
            <tr valign="top">
                <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                    <th class="ms-vh" width="1%" nowrap="nowrap"></th>
                <th class="ms-vh" nowrap="nowrap">Title</th>
                <th class="ms-vh" nowrap="nowrap">Author</th>
                <th class="ms-vh" nowrap="nowrap">Modified</th>
                 < thclass="ms-vh"nowrap="nowrap">Attachments</th > 
            <xsl:call-template name="dvt_1.body">
                <xsl:with-param name="Rows" select="$Rows"/>

Now, locate the dvt_1.rowview template and add a new column with the AttachmentsField control:

 <xsl:template name="dvt_1.rowview">
      <xsl:if test="position() mod 2 = 1">
          <xsl:attribute name="class">ms-alternating</xsl:attribute>
      <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
          <td class="ms-vb" width="1%" nowrap="nowrap">
              <span ddwrt:amkeyfield="ID" 
      <td class="ms-vb">
          <xsl:value-of select="@Title"/>
      <td class="ms-vb">
          <xsl:value-of select="@Editor" disable-output-escaping="yes"/>
      <td class="ms-vb">
        <xsl:value-of select="ddwrt:FormatDate(string(@Modified), 1040, 5)"/>
      <td class="ms-vb">
          <xsl:element name="SharePoint:AttachmentsField">
          <xsl:attribute name="runat">server</xsl:attribute>
          <xsl:attribute name="ListId">
          <xsl:attribute name="FieldName">Attachments</xsl:attribute>
          <xsl:attribute name="ControlMode">Display</xsl:attribute>
          <xsl:attribute name="Visible">true</xsl:attribute>
          <xsl:attribute name="ItemId">
              <xsl:value-of select="@ID"/>

Important: you must change the value of ListId attribute with your list id!



Technorati Tag: Sharepoint Designer,MOSS