tags:

views:

241

answers:

1

Hi,

Using WSS 3.0 I have recently figured out how to aggregate the announcements from several Sharepoint sub-site so that they can be displayed on the top-level site (See: http://stackoverflow.com/questions/1172050/sharepoint-how-to-agregate-announcements-from-sub-sites-onto-main-site).

What I need to do now is to display just the most recent announcement from each of the sub-sites - rather like the SELECT TOP 1 FROM that you might have in SQL. So although each of the sub-site might have several Announcements, I only want to display the most recent one from each of them.

I assumed that this was going to be dead easy - it seems to an obvious sort of thing to want to do, but I just can't find any reference in the docs that I have.

So if anyone knows how to do this, or can point me in the right direction, that would be great.

Thanks.

+3  A: 

This is not possible without custom code (be it XSL or C#). You can do a grouping by WebId when using SPSiteDataQuery (COntextQueryWebPart) and CAML, but you cannot do a top INSIDE the grouping. YOu could try to do each site seperately and set the CAML query's RowLimit to 1 and OrderBy to Created, using ASCENDING='False'

SO the query would look something like this:

<View>
  <ViewFields>
    ....
  </ViewFields>
  <Query>
    <Where>
      ....
    </Where>
    <OrderBy>
      <FieldRef Name='Created' Ascending='False' />
    </OrderBy>
  </Query>
  <RowLimit>1</RowLimit>
 </View>
Colin
@Colin Thanks for your help on this. I can see that it makes sence to do the RowLimit for each sub-site before the merge (or aggregation) but I don't understand where the code should go for that - can you advise?
Simon Knights
Is there a fixed number of subsites?
Colin
@Colin Yes, six sub-sites, and likely to stay that way.
Simon Knights
Then you would be able to create a merged DataSource in SharePoint Designer, targeting each web site individualy with the above query, then use that datasource to bind to a DataFormWebPart, which you can style as you wish. I'll see if I can whip up a small tutorial today.
Colin
@Colin Hi - you have been a great help - I really appreciate your assistance.
Simon Knights
@Colin Thanks! I have had a good play around with this now and have it working exactly as needed. I think I will add my final solution as a new answer - in case it helps anyone else, but you get the Accepted Answer vote.
Simon Knights
Cool! Glad to be of help. Pls add the final solution as an answer as you will not be the last dev who runs into this :-D.
Colin