Displaying the Document Icon in a CrossList SharePoint 2010 DFWP

Once again, I’m finding that the DataForm Web Part (DFWP) acts slightly differently when you’re using it as a roll-up. And, once again, I’m finding great info out there on Marc Anderson’s blog about what I want to do. But, once again, it needs a slight tweak to work with a roll up.

So, if you want to include the document icon in a DFWP when you’re using it in CrossList mode with recursion through sub-sites, instead of this:

<img src="/_layouts/images/{ddwrt:MapToIcon('', ddwrt:GetFileExtension(string(@FileLeafRef)))}" alt="Type" />

You’ll need this:

<img src="/_layouts/images/{ddwrt:MapToIcon('', string(@DocIcon))}" alt="Type" />

DocIcon will need to be included in your FieldRef section of your SelectCommand:

<FieldRef Name="DocIcon"/>

Advertisements

Linking to Documents with a Roll-up DataForm Web Part

Say you want to make a roll-up webpart of all the word documents in a bunch of subsites on SharePoint 2010. Well, you could use the Content Query Web Part and modify the XSLT to filter out everything but word documents. Or, you could fire up SharePoint Designer and pull out the handy-dandy DataForm Web Part.  There’s really nothing new going on here that hasn’t been covered in other blogs. A great resource for getting your head wrapped around the crosslist dataform webpart is Marc Anderson’s blog. The thing that confuzzled me, though, is that when you switch the datasource from a single list, to a recursive crosslist, your data is returned with a number, followed by a semi-colon, followed by the pound sign, followed by the actual data that you want. Argh. Not good, and more Google-spelunking led me to Laura Rogers (@wonderLaura) who pointed me in the right direction on this issue. She’s linking to list items, whereas I’m linking to documents themselves. If you want to link to the documents themselves, it’s a fairly minor change though. Just change this:

{concat('/',substring-after(@FileDirRef,'#'),'/Dispform.aspx?ID=',@ID)}

to this:
{concat('/',substring-after(@FileDirRef,';#'),'/',@LinkFilename)}

(Note, be sure to add the LinkFilename to your selected fields.)

Voila – the name of the document linked to the document itself, no matter which subsite it’s found in.