I posted back in February about using the Data View Web Part to do cross list rollups (See Rolling Up Content in SharePoint Using the Data View Web Part (DVWP)). Since then, I’ve done quite a few of these, and I’ve been meaning for some time to post this update. Not everything that I believed to be true in that earlier post is right all of the time.
It turns out that the CAML is the key to success with this type of DVWP. What it amounts to is something like the following in the selectcommand. (Note that you cannot have any of the white space or comments I show below to describe it if you want it to work!). This is from a client example, but you should be able to get the gist of it for your situation.
<View>
// This says to grab from all child webs recursively.
<Webs Scope='Recursive'></Webs>
// ServerTemplate 100 is 'General List', i.e., Custom Lists.
// See the 'Type' attribute on the page at http://msdn.microsoft.com/en-us/library/ms462947.aspx
// for descriptions of the various values that are available.
<Lists ServerTemplate='100'></Lists>
<View>
<Query>
<Where>
<Eq>
// Only grab items which have ContentType of 'Finding'. This isn't required,
// but if you do not make it explicit, you will also get any items
// which have all of the columns below in the <ViewFields>.
<FieldRef Name='ContentType'/><Value Type='Text'>Finding</Value>
</Eq>
</Where>
</Query>
// In a CrossList Data Source, the <ViewFields> are what matters
// when it comes to specifying columns.
// <DataFields> has no effect whatsoever, and can even be removed.
<ViewFields>
<FieldRef Name='ID'/>
<FieldRef Name='Title'/>
<FieldRef Name='AuditTitleCT'/>
<FieldRef Name='AuditorCT'/>
<FieldRef Name='CompleteDateCT'/>
<FieldRef Name='RiskCT'/>
<FieldRef Name='FileDirRef'/>
</ViewFields>
</View>
</View>
The DataSources section will end up looking something like below:
<DataSources><SharePoint:SPDataSource runat="server" DataSourceMode="CrossList" UseInternalName="true" selectcommand="<View><Webs Scope="Recursive"></Webs><Lists ServerTemplate="100"></Lists><View><Query><Where><Eq><FieldRef Name="ContentType"/><Value Type="Text">Finding</Value></Eq></Where></Query><ViewFields><FieldRef Name="ID"/><FieldRef Name="Title"/><FieldRef Name="AuditTitleCT"/><FieldRef Name="AuditorCT"/><FieldRef Name="CompleteDateCT"/><FieldRef Name="RiskCT"/><FieldRef Name="FileDirRef"/></ViewFields></View></View>" id="dataformwebpart2"></SharePoint:SPDataSource></DataSources>
One other thing to note: It didn’t make one bit of difference in my testing what the WebURL was set to or even if it was there. All items in the current Web (Site) and any below it in the Site Collection topology are returned. You could obviously control this further by either adapting your topology or adding more constraints in your Where clause in the CAML.
Note added 23 September 2008: When you add your columns to the ViewFields section, you may see that the first underscore character is encoded as _x005F_. In other words, a column named Expiration Date, which would normally have the internal name of @Expiration_x0020_Date is shown as @Expiration_x005F_x0020_Date. You actually will need to change the column references in your XML to reflect this oddity.
15 comments
3 pings
Marc Anderson
October 14, 2008 at 8:56 pm (UTC -5)
No name
October 6, 2008 at 8:56 pm (UTC -5)
Marc Anderson
September 24, 2008 at 8:56 pm (UTC -5)
shikari
September 24, 2008 at 8:56 pm (UTC -5)
kento
September 24, 2008 at 8:56 pm (UTC -5)
Brett
May 7, 2009 at 10:30 am (UTC -5)
I know this is an old post but it’s one of the few (only?) ones that touched on the WebURL property.
I have all of this working properly but I would like to place the completed web part in a different place in the site, but have it reference a site (and subsites) not in the path. Consider this:
root
–Blogs Publishing Site
—-Blog Site 1
—-Blog Site 2
—-Blog Site 3
–Admin Site
—-AdminTool Page (containing my web part)
My web part displays all the subsite blogs and makes it easy to update a custom column (“IsFeatured”) on any posts within any of those blogs, from one location (otherwise, someone would have to drill into each blog and set “IsFeatured” to true or false in order to show or hide a given post on the front page). But I want this and other similar site-wide tools to reside in one place.
My control works fine if I place it in a page under “/Blogs”, but in the AdminTool Page I can’t figure out how to tell the SPDataSource in CrossList mode to look at “/Blogs”. Any ideas at all, or am I missing something fundamental?
Marc
May 7, 2009 at 10:52 am (UTC -5)
Brett:
Nice approach. I like what you’re doing.
As with all things SharePoint, there’s probably more than one way to do this, but here’s an idea. Another option on Webs is Scope=SiteCollection. This says to grab content from *everywhere* in the Site Collection.
See this MSDN article for more details:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.webs.aspx
I assume that you are already filtering for the blog list type by using:
I think that might get you what you want. Another filter which you could apply would be to filter on the path for the items themselves to limit to only items which have paths which start with ‘/Blogs Publishing Site’. (This would help if you are using blog lists somewhere other than in the ‘Blogs Publishing Site’ path.)
Hope this helps.
M.
Brett
May 7, 2009 at 11:51 am (UTC -5)
Well, after posting I of course kept searching and of course then found the answer. From an MSDN blog (http://blogs.msdn.com/joshuag/default.aspx), I found that he was referencing the WebUrl parameter using inside . So my working Data Source looks like:
<SharePoint:SPDataSource runat=”server” UseInternalName=”true”
DataSourceMode=”CrossList” Scope=”Recursive”
SelectCommand=”"
id=”DataSrc1″>
And I am happy. Thanks for the quick response, hope this helps somebody.
Brett
May 7, 2009 at 11:58 am (UTC -5)
I see that WordPress didn’t like my markup. The tag that’s required is:
<SharePoint:SPDataSource runat=”server” UseInternalName=”true”
DataSourceMode=”CrossList” Scope=”Recursive”
SelectCommand=”< Webs Scope=’Recursive’>
</ Webs>
<Lists ServerTemplate=’301′ BaseType=’0′>
</Lists>
<View>
<ViewFields>
<FieldRef Name=’Title’/>
<FieldRef Name=’ID’/>
<FieldRef Name=’Body’/>
<FieldRef Name=’FileRef’/>
<FieldRef Name=’PublishedDate’/>
<FieldRef Name=’_ModerationStatus’/>
<FieldRef Name=’IsFeatured’/>
<FieldRef Name=’Modified’/>
</ViewFields></View>” id=”DataSrc1″>
<SelectParameters>
<asp: Parameter runat=”server” Name=”WebUrl” DefaultValue=”/Blogs/”/>
</ SelectParameters >
</SharePoint:SPDataSource>
HI Marc
December 2, 2009 at 2:31 pm (UTC -5)
HI MARC
I am working on Creating Webpart for Content Rollup using DVWP and i Follow your Link
I have Created Datasource as per below
<Webs Scope='Recursive'
Project Team Member
but it does not return any Data even though i have data in it.
can you please advise whats wrong with this
Thanks
Marc
December 2, 2009 at 2:43 pm (UTC -5)
Unfortunately your code didn’t come through on your comment. (It’s a WordPress thing.) Can you try to send me your code through the Contact page?
M.
anonymous
January 31, 2012 at 2:26 pm (UTC -5)
Hi Marc,
When I add certain fields in the tags, the data view displays “the server returned a non-specific error”
These are all site columns that are part of the site content type. Do you know of any reason why certain columns would cause that error and others don’t?
Thanks for all your contributions to the SharePoint world!
Marc
January 31, 2012 at 2:48 pm (UTC -5)
Odds are the you’re just typing something wrong. Make sure that your syntax is correct and the you are using the StaticNames for the columns. also note that your CAML must be escaped; what I show in the post is prettied up to help make it clearer.
M.
1 2 Next »
Fun With My Blog Stats « Marc D Anderson’s Blog
April 11, 2009 at 8:20 am (UTC -5)
[...] Rollup Data View Web Parts Revisited 67 views [...]
Displaying Columns in a Crosslist DVWP « Marc D Anderson’s Blog
April 21, 2009 at 10:50 am (UTC -5)
[...] Categories: Uncategorized Tags: CAML, Crosslist, SharePoint, SharePoint Designer I’ve alluded to this in the past, but I had a client situation in the last few days that brought it top of mind again. One of the [...]
Linking to Documents with a Roll-up DataForm Web Part « Blah-de-blah-blog
May 16, 2011 at 2:31 pm (UTC -5)
[...] 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, [...]