Rolling Up Blog Posts

Filed under:IT,SharePoint — posted by Jason MacKenzie on September 2, 2009 @ 5:40 pm

I was recently presented with the following scenario:  As part of the creation of a SharePoint dashboard, my business users are interested in seeing the number of blog comments and their current status by blog.

Our blogs are contained as subsites of a site called Blog Central which reside in a site collection called “Public.”  The dashboard resides in a separate site collection.  Our site collections contain individual content databases.

As a former developer, my initial response is to find an out of the box solution wherever possible. 

  1. A content query web part wouldn’t suffice as its scope is limited to the current site collection
  2. Adding a new data connection in SP Designer to hook up to a dataview web part (DVWP) won’t work because the lists and libraries (not the web services) are also limited to the current site collection. These can be combined to recursively roll up content in the current site collection however.

I ended up querying the content database directly and presenting that through the DVWP.  So, in SP Designer I created a new Database Connection.  Database_Connections

 

 

 

 

Browsing to the content database for the Public site collection I wrote the following query in order to retrieve the correct data:

SELECT     Webs.Title,
                    CASE UserData.tp_ModerationStatus
                                   WHEN 0 THEN ‘Approved’ 
                                   WHEN 1 THEN ‘Rejected’ 
                                    WHEN 2 THEN ‘Pending’
                     END AS Status,                        
                      COUNT(*) AS Total 

FROM       AllLists INNER JOIN                       
                    Webs ON AllLists.tp_WebId = Webs.Id INNER JOIN 
                     UserData ON AllLists.tp_ID = UserData.tp_ListId 

WHERE     (AllLists.tp_Title = ‘comments’) AND
                      (Webs.FullUrl LIKE ‘%blogcentral%’) 

GROUP BY UserData.tp_ModerationStatus, Webs.Title 

ORDER BY Webs.Title, UserData.tp_ModerationStatus

I then conditionally formatted the DVWP to show different colours based on status and done.  
DVWP

 

 

 

If there is a better way to do this, using CAML or some other method,  please let me know and I will share it.

Bookmark and Share
VN:F [1.9.3_1094]
Rating: 9.0/10 (2 votes cast)
VN:F [1.9.3_1094]
Rating: +1 (from 1 vote)
Rolling Up Blog Posts, 9.0 out of 10 based on 2 ratings

Popularity: 4% [?]

Share and Enjoy:
  • Facebook
  • Digg
  • del.icio.us
  • Sphinn
  • Mixx
  • Google Bookmarks
  • StumbleUpon

2 comments »

  1. That isn’t really recommended.

    To do cross site collection data aggregation, you need a tool like lightning tools lightning conductor web part,http://www.lightningtools.com/pages/lightning-conductor-web-part.aspx.

    Speaking with some other Sharepoint people, we would highly advise to get rid of that query as directly querying the content databases is not recommended. Generally speaking it will take you out of support if you are querying the DBs directly, it is recommended to do it through the object model or web services.

    Reply to eric

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: +1 (from 1 vote)

    Comment by ericNo Gravatar — September 3, 2009 @ 6:10 am

  2. Just to clarify for any future references: Reading database content does NOT void warrenty/microsoft support agreements. Only modification of the databases, or their content does.

    It is not recommended for a variety of reasons (if the schema, or structure changes in a Microsoft Update or Release then the query would no longer be reliable), but often can still be benificial. Many third party components and especially reporting solutions run queries on databases all the time. Since this is also a reporting solution I see no real issues with executing it like this.

    A custom developed component, third party tool like lightning tools, or SharePoint search might have also been viable alternatives.

    Just thought I would clarify Microsoft’s support stance and offer my two cents.

    Hope this helps,
    Richard Harbridge

    Reply to Richard Harbridge

    VA:F [1.9.3_1094]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.3_1094]
    Rating: +2 (from 2 votes)

    Comment by Richard HarbridgeNo Gravatar — September 8, 2009 @ 5:41 am

Copy link for RSS feed for comments on this post or for TrackBack URI

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required)




image: detail of installation by Bronwyn Lace