Friday, October 22, 2010

Display SharePoint ListItem's Attachments

Steps to create a separate page to display all the attachments of a particular SPListItem using SharePoint Designer:

1. Create an ASPX page using SharePoint Designer (SPD).

2. Add a DataView control in page in-between HTML form tag.
Note: First save the page then add control.

3. Select the Data Source Library.
Select your SharePoint List (in my case it is MyTest SPList). Open its context menu and select Show Data

4. Select columns you want to keep in Data Source Details.

5. Insert Selected Fields as Single Item View

6. Now some code changes:
a. Add some CSS style above closing head tag [optional]
<style type="text/css">
.ms-vb a

b. Place your selected columns/fields
Location followig code snippet:
<xsl:template name="dvt_1.rowview">

and insert following code in-between them:

<xsl:template name="dvt_1.rowview">[Original code - 1]
<tr style="color:maroon;font-weight:bold; font-family:Tahoma; font-size:small;">
<tr class="ms-alternating" style="font-family:Tahoma; font-size:x-small;">
        SharePoint ListItem ID - <b><SharePoint:FieldValue FieldName="ID" ControlMode="Display" runat="server" Visible="true" /></b>
<tr class="ms-formbody" style="font-family:Tahoma; font-size:xx-small;">
        <SharePoint:AttachmentsField ControlMode="Display" FieldName="Attachments" runat="server" Visible="true"/>
<tr style="display:none;">[Original code - 2]

Note-Here we are hiding the existing TR row

c. Hide paging control
Locate following code snippet:

<td nowrap="" class="ms-paging" align="right">

and hide that TD.
changed snippet:

<td style="display:none;" nowrap="" class="ms-paging" align="right"> 

7. Now open the page in browser and passed SPListItem as query string.
example: http://[server-name]:[port-number]/[page-name].aspx?ID=1


shekar said...

hi Avinash,
i went through your blogs, ur blogs are very simple and easy. i need some help from u, i am trying to show the names of how many users are currently logged into the sharepoint site.
please help me how to do this

thanks in advance

Avinash said...

Hi Shekar,

Please check following links-