Sharepoint Tips #1
How to customise a Sharepoint list with attachments
This problem is pretty well documented across the MSDN forums and developer lists – only recently did I come across a solution, so in the interests of helping out anyone else who has spent months trying to get this to work – here’s a brief how-to. It assumes basic knowledge of Sharepoint Designer, MOSS 2007, and a bit of XSL.
You will also need the latest patches for MOSS 2007 which allow attachments to be displayed in customised data views of lists.
What we will create is a summary view of a list which contains ‘more…’ links to a full view of a list item, where you can download the attachment.
Step 1 – AllItems.aspx
Create a new List which you wish to customise. Open AllItems.aspx and customise it as an XSL Data View – or alternatively, if you wish to display your data on the default.aspx of your site, create a data view. Select a few fields to display which make a good summary, and format it as you wish. If you are using AllItems.aspx I recommend saving this under another name such as ‘CurrentItems.aspx’ so you don’t lose your ability to edit list items.
Create a link somewhere in the dvt_1.rowview template in the format:
<a href="disp.aspx?ID={@ID}">More...</a>
This will link you to a single item display page that we are about to create, and passes the ID of the item to be displayed.
Step 2 – DispForm.aspx
Next open up DispForm.aspx and revert to its Master page’s content.
Create a Single Item data view of your list on this page showing all of its fields. Include the Attachments field.
In the dvt_1.rowview template replace the Attachments tag with this:
Attachments: <SharePoint:AttachmentsField ControlMode="Display"
FieldName="Attachments" runat="server" Visible="true"/>
Now we need to set a Parameter for the List Item ID so that the page will display the corresponding details of an ID passed to it: click to show Common Data View Tasks and click on Parameters. Add a new Parameter called ListItemID. For Parameter Source select Query String, for Query String Variable enter ID and for Default Value enter 0. (Lists begin their first item with an ID of 0).
Next click on Filter and check the box at the bottom marked ‘Add XSLT Filtering’. Click Edit.In the section marked ‘Edit the XPath expression’ enter:
[@ID=$ListItemID]
Click OK, OK again to exit the Filter menu, and save this page as ‘disp.aspx’. Notice that this corresponds with the hyperlink we added above.
Now go to Paging and ensure that your list is set to display all items, not just a single item.
If you’ve set this all up correctly you should now have a full view of your list, which links to a single item view displaying the corresponding attachment for download!
I’m still getting to know XSL and MOSS so I am yet to get a list to display multiple items with corresponding attachments, but I’m sure its a case of fiddling around with parameters…