I’ve been working lately on customizing the output of the Content Query Web Part that comes with MOSS. There are a couple of good walk-throughs out there that get you pointed in the right direction. (See http://blogs.msdn.com/ecm/archive/2006/10/25/configuring-and-customizing-the-content-query-web-part.aspx and http://www.microsoft.com/belux/msdn/nl/community/columns/stevenvandecraen/contentquerywebpart.mspx for example…)
One thing that you run up against almost immediately is that in order to pull the values for any columns other than the title, you need to specify the encoded column name and its appropriate type. This gets glossed over a bit in the walk-throughs.
Now, the encoded column name isn’t too much of a problem. You’re most likely dealing with spaces, so _x0020_ is all you’ll ever see. (Things get more complicated obviously if you do something clever like name a column "_x0020_") At any rate, you can always figure out what the encoded value of any string would be by using the EncodeLocalName method of the System.Xml.XmlConvert class.
The type can be a little more of an issue. I couldn’t find a list of these in the sdk documentation. It might be there, or might be coming soon now that MOSS has RTM’d. As I said, I couldn’t find it though…
So after a little stumbling around in the WSS_Content database, I found what I needed. The following queries will tell you everything you need to know about your column:
SELECT Definition
FROM [WSS_Content].[dbo].[ContentTypes]
where definition like ‘%My Column Name%’
FROM [WSS_Content].[dbo].[ContentTypes]
where definition like ‘%My Column Name%’
SELECT tp_fields
FROM [WSS_Content].[dbo].[AllLists]
where tp_Title like ‘%My List Name%’
FROM [WSS_Content].[dbo].[AllLists]
where tp_Title like ‘%My List Name%’
The first query handles the scenario where you’ve created your own content type. The second is when you’re just dealing with a sharepoint list.
Of course, you need to make sure you’re in the right WSS_Content database. Check in the Central Admin Site Collection List if you’re not sure.
The queries both give you back a gob of xml that describes your column. (The second one actually gives you info on all the columns in the list…) You can pick out the encoded name, the type of the field, etc.
This is probably more than obvious to someone who’s spent a lot of time spelunking through the WSS_Content schema. I post it here in the hopes that it will save someone the hour or two that I lost on it…
MB