Posts Tagged ‘Crosslist

10
Sep
09

Roll Up Blog Posts in a Site Collection

I got a quick question today from a client asking how to roll up blog posts.  He wanted to display the latest blog posts from all of the blogs which executives have in the Site Collection, which is used as the organization’s Intranet.

He had the idea right, using a Data View Web Part (DVWP) with the DataSourceMode=”Crosslist” and the Webs Scope=”SiteCollection”.  However, he got trapped by a cut and paste gotcha.

Since he wanted to only show the latest blog posts, he needed to set the correct value for ServerTemplate.  The CAML he had copied had <Lists ServerTemplate=’104′></Lists>, which specifies lists which are based on the ‘Announcements list’ template.  The value for the ‘Blog posts’ template is <Lists ServerTemplate=’301′></Lists>.

The possible values for ServerTemplate can be found in this MSDN support article, and here they are listed for ease of use:

  • 100   Generic list (this means any Custom List)
  • 101   Document library
  • 102   Survey
  • 103   Links list
  • 104   Announcements list
  • 105   Contacts list
  • 106   Events list
  • 107   Tasks list
  • 108   Discussion board
  • 109   Picture library
  • 110   Data sources
  • 111   Site template gallery
  • 112   User Information list
  • 113   Web Part gallery
  • 114   List template gallery
  • 115   XML Form library
  • 116   Master pages gallery
  • 117   No-Code Workflows
  • 118   Custom Workflow Process
  • 119   Wiki Page library
  • 120   Custom grid for a list
  • 130   Data Connection library
  • 140   Workflow History
  • 150   Gantt Tasks list
  • 200   Meeting Series list
  • 201   Meeting Agenda list
  • 202   Meeting Attendees list
  • 204   Meeting Decisions list
  • 207   Meeting Objectives list
  • 210   Meeting text box
  • 211   Meeting Things To Bring list
  • 212   Meeting Workspace Pages list
  • 301   Blog Posts list
  • 302   Blog Comments list
  • 303   Blog Categories list
  • 1100   Issue tracking
  • 1200   Administrator tasks list
21
Apr
09

Displaying Columns in a Crosslist DVWP

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 quirks of a Crosslist DVWP is that you *must* specify all columns you would like to display in the CAML for the Data Source. You can add any column in the XSL you want, but if they aren’t explicitly specified in the CAML, you will get blank results.

Here’s an example. Say you want to gather the latest announcements from across the Site Collection for display on the Home Page of your Intranet. You’re displaying the latest 5 announcements, but you realize that annoucements that are expired are still showing up. So, you add a filter to the row select, as below, and you’re not seeing what you’d expect.

<xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[
    (ddwrt:FormatDateTime(string(ddwrt:Today()), 1033, 'yyyyMMdd') >=
    ddwrt:FormatDateTime(string(@Expires), 1033, 'yyyyMMdd')) or
    string-length(@Expires) = 0
  ]"/>

You’ll need to add an explicit FieldRef for the Expires column in your CAML, as below.  (I’ve added carriage returns and white space into the CAML above for readability, but you can’t have them in your DVWP.)

<SharePointWebControls:SPDataSource
  runat="server"
  DataSourceMode="CrossList"
  SelectCommand="
    <View>
      <Webs Scope='SiteCollection'></Webs>
      <Lists ServerTemplate='104'></Lists>
      <ViewFields>
        <FieldRef Name='ID'/>
        <FieldRef Name='Title'/>
        <FieldRef Name='Body'/>
        <FieldRef Name='FileDirRef'/>
        <FieldRef Name='Created'/>
        <FieldRef Name='Author'/>
        <FieldRef Name='Expires'/>
        <FieldRef Name='PermMask'/>
      </ViewFields>
    </View>"
  UseInternalName="true"
  ID="dataformwebpart5">
</SharePointWebControls:SPDataSource>

Once you add the FieldRef to the CAML, the Expires column values are available for use in your filter.

Keep in mind that you need to be careful what you add into your <Viewfields> section. If you add a FieldRef for a column which doesn’t occur in *all* of the items which you want to retrieve, you will, in effect, be adding a filter to the CAML. Only items which have all of the columns specified in the FieldRefs will be returned.

21
Sep
08

Rollup Data View Web Parts Revisited

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=&quot;Recursive&quot;></Webs><Lists ServerTemplate=&quot;100&quot;></Lists><View><Query><Where><Eq><FieldRef Name=&quot;ContentType&quot;/><Value Type=&quot;Text&quot;>Finding</Value></Eq></Where></Query><ViewFields><FieldRef Name=&quot;ID&quot;/><FieldRef Name=&quot;Title&quot;/><FieldRef Name=&quot;AuditTitleCT&quot;/><FieldRef Name=&quot;AuditorCT&quot;/><FieldRef Name=&quot;CompleteDateCT&quot;/><FieldRef Name=&quot;RiskCT&quot;/><FieldRef Name=&quot;FileDirRef&quot;/></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.




 

January 2010
M T W T F S S
« Dec    
 123
45678910
11121314151617
18192021222324
25262728293031

Twitter Updates