Thursday, January 26, 2012

Displaying attachments in a DataFormWebPart

A little problem I ran across on a recent project. I needed to display the attachements link for a list item in a custom DataFormWebPart.

The first thing I did was to add the attachment column to the DataFormWebPart all this resulted in was a yes or no value. After a bit of searching on the web I found the solution. The following lines need to be added:

<SharePoint:AttachmentButton ControlMode="Edit" Enabled="true" ItemId="{@ID}" runat="server" Visible="false"/>
<SharePoint:AttachmentsField ControlMode="Display" ItemId="{@ID}" EnableViewState="true" FieldName="Attachments" runat="server"/>

Relevant links:
http://support.microsoft.com/kb/953271
http://social.technet.microsoft.com/Forums/en-US/sharepointsocialcomputing/thread/80a27347-fbc3-40e0-a622-cce5675579c4/  
http://social.msdn.microsoft.com/Forums/en/sharepointcustomization/thread/c257a894-859a-406c-b3bd-d021ef1b7a75

No comments: