Wednesday, October 26, 2011

Show Attachment File Names in a List View

Saw a cool way to modify a list view to show the attachment filenames.  Original post is from Alex Dean here and I wanted to expand upon it:

1) Open the site up in SharePoint Designer, click on the list where you'd like to add the column with filenames, and pick the view that you'd like to edit (e.g. AllItems.aspx)

2) Right click on the area displaying the view and select "Convert to XSLT Data View"

3) Then view the new web part, and search for the header row (it begins with):

                <!--Attachments--><TH nowrap="" scope="col" class="ms-vh-icon">

after the </TH>, add the following:

              <TH nowrap="" scope="col" class="ms-vh2">File Names</TH>

4) Scroll down a bit until you hit the rows:

            <!--Attachments-->
            <TD Class="{$IDAKFYXG}">
                <xsl:if test="not (@Attachments=0)"><img border="0" src="{$HttpVDir}/_layouts/images/attach.gif" /></xsl:if>
            </TD>

and add the following afterwards:

            <td>
                <SharePoint:AttachmentsField
                    ControlMode="Display"
                    ItemId="{@ID}"
                    FieldName="Attachments"
                    runat="server"/>
            </td>

Press save and you should see the filenames show up in your List View!