Thursday, October 18, 2012

AttachmentField control in SharePoint


The SharePoint AttachmentsField is used to display attachments from an SP list item.

<td align="center" id="att_{@ID}">
<xsl:if test="@Attachments='1'">
<SharePoint:AttachmentsField ID="att{@ID}" ControlMode="Display" ListId="{$ListID}" ItemId="{@ID}" FieldName="Attachments" visible="true" runat="server" />
</xsl:if>
</td>

The HTML that is rendered includes a table with a row for each attachment. The anchor tag look something like:

<a href="/student-affairs/athletics/athletics-w/basketball/Lists/Schedule/Attachments/11/statistics.html">20090312.6.html</a>

Mod operator to control Table Rows in XSL


The Mod operator returns the remainder left after division is performed. If you have a table and you need to have a certain amounts of columns before another row is created, use the mod operator.

The following example will create a new row after 3 columns are created.

<xsl:if test="position() mod 3 = 1">
<xsl:text disable-output-escaping="yes"><![CDATA[ <tr> ]]></xsl:text>
</xsl:if>
   <td valign="top">
    <img alt="" src="{@ImgURL}"/>
    <xsl:call-template name="dvt_2" />
   </td>
<xsl:if test="position() mod 3 = 3">
<xsl:text disable-output-escaping="yes"><![CDATA[ </tr> ]]></xsl:text>
</xsl:if>