Wednesday, April 25, 2012

Display Item Attachments in SharePoint List View

It is very easy to display list item attachments
in List View and also manipulate the display of attachment, like if attachment is
image, we can display image not just a link.
1. Open List View in SharePoint Desinger
2. Add new column titled "Attachments".
3. Select TD tag of New column.
4. Replace selected code with below code.


 <td id="ItemAttchment" class="ms-vb">
          <xsl:element name="SharePoint:AttachmentsField">
          <xsl:attribute name="runat">server</xsl:attribute>
                    <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"/>
          </xsl:attribute>
          </xsl:element>
</td>


5. View with Attachments

33 comments:

  1. I had a problem after pasting the XSLT code from Step 4. The following error showed in the table cell of the new column:

    Error Rendering Control - Unnamed1Cannot create an object of type 'System.Int32' from its string representation '3af427e6-b3f9-4313-96b7-bde7bf693afd' for the 'ItemId' property.

    ReplyDelete
    Replies
    1. Had the saqme Problem - you're getting the ID of the Attachment column, you need to select the ID of the Sharepoint List Item:
      <xsl:value-of select="$thisNode/@ID"></xsl:value-of>
      Hope this works for you

      Delete
    2. I had the same problem and tried Martin solution but still I have the same problem. Any ideas?

      Delete
  2. Hi, Any idea if this can be done to a XsltListViewWebpart added dynamically to a list form?

    ReplyDelete
  3. It seems that if the attachment isn't added to the list item initially OR the attachment is changed for that list item later, it doesn't update the link on the view.

    ReplyDelete
  4. thanks...great work...helped me before my presentation !!!!!

    ReplyDelete
  5. Yes it is working fine , thanks for sharing such a nice information it was really helpful.

    ReplyDelete
  6. It seems that if the attachment isn't added to the list item initially OR the attachment is changed for that list item later, it doesn't update the link on the view.

    ReplyDelete
  7. While sorting the view the attachments are not been sorted

    ReplyDelete
  8. How could I sort the attachments when the list items are sorted?

    ReplyDelete
  9. Hi, That's all working great, but how can I display the URL to the attachment as an image? Thanks.

    ReplyDelete
  10. Dinesh and Luis, Did you figure out a way to avoid the issue of attachment displaying old file when we modify the attachment or sort the list?
    Thanks
    Nate

    ReplyDelete
  11. can we change the display name of attachments? for example, more information instead of amit_cv.docx

    ReplyDelete
  12. Hi. I also have a problem with the sort of attachments. When you apply a filter attachment does not correspond to the list items.

    ReplyDelete
  13. Hi there - How to do this in SharePoint 2013? Designer doesn't show Design view window.

    ReplyDelete
  14. Hi there - I was able to achieve it but now the problem is that since I customized the View page, It is not coming in the list of views and hence i couldn't export items to Excels. :-(

    Thanks Amit for posting this article. In a way your article was helpful.

    ReplyDelete
  15. How to do this in SharePoint 2013? Designer doesn't show Design view window.

    ReplyDelete
  16. How to do it on SharePoint 2013 ?

    ReplyDelete
  17. Can you help with the multiple attachments within a list entry. I am able to display the attachments now and want to show "last modified by" for each of them ? Any pointers ??

    ReplyDelete
    Replies
    1. Santosh, I'm trying to figure this out too, have you had any luck?

      Delete
    2. I tried this, but no success, I could not able to find the XSLT file. I am using SharePoint O365. so I followed steps from below url and it worked.


      https://social.technet.microsoft.com/Forums/en-US/74dac191-5a9e-4970-a9f6-a501846f0bef/forum-faq-show-attachments-in-sharepoint-2013-custom-list-view?forum=sharepointgeneral&prof=required

      Delete
  18. Very nice article. Working fine for lists. But I was unable to get this to work for form library.

    I have a form library with an attachment field. So when the form gets submitted I need the hyperlink of the attachment in the SharePoint list view. Any suggestions??

    ReplyDelete
  19. Thanks for the help that works perfectly after replacing

    ReplyDelete
  20. The attachments are not sorting when you change the sorting in any of the other columns, is there a fix for this?

    Thanks

    ReplyDelete
    Replies
    1. I suppose I should clarify that it is not filtering when I filter another column.

      Delete
  21. where exactly do i have to paste the code?

    ReplyDelete
  22. I was able to use this for SP2010, but we are now moving to SPOnline (using SPD2013). Do you have a similar solution when SPD2013 does not allow Design or Split mode?

    ReplyDelete
  23. Yes also wondering how to do this in SPD 2013 ? Thx

    ReplyDelete