Category Archives: List Forms

Displaying List Attachments in Custom List Forms

As some of you may already know, there is a problem with the SharePoint List attachments functionality if you use Custom List Forms: you lose it all. If you create a custom NewForm.aspx or EditForm.aspx, with a custom List Form control, the ability to add or delete attachments to a list item disappears.

Marc Davis has described a workaround on his Blog here, which is not supported by Microsoft, but works well.

Recently I encountered a situation at a customer’s site, where only the DispForm.aspx had to be modified, because of some required re-formatting of list item values. I figured I didn’t have to go through the whole process described by Marc, since all I wanted back was the functionality to display the list item attachments, not the upload and delete functionality (the NewForm.aspx and EditForm.aspx didn’t need any customization, and these pages have the proper attachment functionality in place).

This turned out to be quite easy: you can use the SharePoint control AttachmentsField.

Here’s the code I added in the dvt_1.rowview XSL template, part of the DataFormWebPart that SharePoint Designer creates for you when you insert a Custom List Form:

     <tr>
      <td width=”190px” valign=”top” class=”ms-formlabel”>
       <h3 class=”ms-standardheader”>
        <nobr>Attachments</nobr>
       </h3>
      </td>
      <td width=”400px” valign=”top” class=”ms-formbody”>
       <SharePoint:AttachmentsField ControlMode=”Display” FieldName=”Attachments” runat=”server” Visible=”true”/>
      </td>
     </tr>

That’s it! Your list item attachements are back in your custom DispForm.aspx

P.S.: Of course, you should never edit your DispForm.aspx directly, but always leave it intact and create a new aspx page, based on the DispForm.aspx.

Update 16-09-2008:

I found out today, that Microsoft has released a knowledge base article a few days ago about this issue. It seems they have solved the issue regarding the adding and deleting of attachments in the Infrastructure Update for SharePoint. You still have to do some XSL editing, but hey, since you are creating a custom list form, my guess is you are doing this already. You can find the knowledge base article here: http://support.microsoft.com/kb/953271