Using SharePoint:AttachmentsField in a DVWP’s XSL

Here’s proof that you should never stop learning (or at least trying to learn). I ran across a post on the MSDN SharePoint – Design and Customization forum just now that showed me a trick I’d never run into before. I don’t know that I’ve ever had the need to show file attachments for items in a SharePoint list using a Data View Web Part (DVWP) before, but this is a really nice trick to do it.

You can add the following chunk of XSL into the dvt_1.rowview template (or anywhere else where you are in the context of a single node):

Here’s a rather ugly, simple little example, but it should get the point across. Note that the item with the Title = “Tue Aug 25 11:52:42 CDT 2009” has two attachments, and both are shown. The attachment names are links that allow you to open the attachments, too.

Now that I know the trick, some Binging shows me that lots of others have known all along. See, keep learning!

I wonder if there are other things like this, as well. I did a little rooting around trying to figure out where the SharePoint:AttachmentsField is actually coming from in the hope of finding more capabilities, but I didn’t have any luck. Any ideas?

I’ve used it successfully in my SharePoint dataview. Now I’m looking for how to further customize the table generates. Say I wanted to parse out the file extentions or apply other custom formatting to the table. Do you have any idea how I’d go about that? I imagine I need to pass the to a but am at a loss how to get started.

I’ve used it successfully in my SharePoint dataview. Now I’m looking for how to further customize the table SharePoint:AttachmentsField generates. Say I wanted to parse out the file extentions or apply other custom formatting to the table. Do you have any idea how I’d go about that? I imagine I need to pass the TABLE to a TEMPLATE but am at a loss how to get started.

I am using this, and I got it to work for the most part. However, I have editing enabled on the DVWP. When I view the page, and click to edit an item, and then save, I come back to the page and every item has the same attachments listed for it. If I leave the page and come back, though, it’s all back to normal. Any way around this behavior?

Amit asked a similar question above. I just did a little Binging and found this post with a solution that’s supposed to work, but it doesn’t in my environment. Can you try it and let me know how it goes?

I’m hoping we can solve this before SPTechCon, but sure! It’ll be nice to meet you.

I just spent some more time on this, and it’s a puzzler. I probably found all of the same articles you did, and I even saw a comment from you on one of them. There’s got to be something we’re missing that will get the context right for the SharePoint:AttachmentsField control.

I am using Marc’s code in the following way. I have two DVWPs on a page (within a MOSS site), a master/detail scheme. My customer wants the attachments to show where by default all you see is ‘Yes’ or ‘No’.

in the XSL code (picked up from the XSL editor under Modify Web Part), I simply replaced the word ‘Yes’ with Marc’s code block.

Think you’ve got great Active Directory data?

Try the FREE Hyperfish Analyzer
Find out just how bad your Active Directory data really is. In your custom report you will see how you are faring with key attributes including Profile Pictures, Phone Numbers, and Job Titles, as well as learn the value of an up to date Directory.