Sunday, January 3, 2010

Showing Attachments in List Views

Came across this one for one of my custmers. Wants an ability to upload documents to a list item and then show the uploaded docuuments on the list view.
The solution here is to use Attachments and try to get them to show on the view. By default the Attachments field will only give back a true/false value of 0/1, which is only useful for highlighting the fact that there are attachments.
You can build SharePoint Controls into your views and the one you need to show all the attachments as links is the AttachmentField

The best place to put this control is in your dataviews. Either create one in SharePoint Designer from scratch or convert an existing view into a DataView through righ clicking it in SPD 2007 and choosing "convert to XSLT DataView". Once converted you can add the control to the page.
But beware. When creating it from scratch you will be missing the Namespace directive (xslns) which ensures that the xsl parser does not get confused with your ASP.NET code. Best bet here is to convert a view and have a look at all the xslns entries it puts in there. It will enlighten you.


Jessica said...

where exactly would you put this code? I have an out of the box Email List View, and I want to be able to show an "Attachments" column. Please advise. Thanks in advance!

alx said...

Ah, so sorry. I should have been more precise.
This only works when you convert your view into an XSLT Dataview using SharePoint Designer.
Simply right click on the view in SPD and you should get the convert to xslt option. Once converted you can do many wonderful things including adding such controls.

xyzboy said...

You are a lifesaver. Is this a recent discovery? I've tried to address this before and wasn't able to find a solution.

xyzboy said...

You are a lifesaver. Is this a recent discovery? I've tried to find a solution to this before and couldn't find anything. Thanks for posting, you've made my life much easier.

alx said...

I actually figured this one out all by my self early last year. But it was not a failsafe solution, as the formatting was not easy to control.

sprsprspr said...

Thanks for the post! It worked beautifully. I just noticed that when you sort by any of the columns, that the filenames no longer match up correctly. Any ideas how to get around that? I can see the IDs being passed to the control are correct, but the control only shows the first filename(s) on a sort...

Alex Dean said...

Sorry but I have no fast answer on that one. The dataviews do get iffy the more you customise them.

lsalery82 said...

where do you add the control once you have converted the view to XSLT?

Alex Dean said...

Anywhere in the XSL where you want it to appear!