Skip to content

Reply to Comments in SharePoint 2010 Blogs

September 5, 2011

Overview (call it – The Gripe Zone)

SharePoint 2010 blogs are direct descendants of MOSS blogs.  That is not happy news for developers, as the blog features is awkwardly put together with no real API access and mysterious, undocumented inter-connections among its lists that are not very SharePoint-like.

These facts make SharePoint blogs notoriously hard to customize unless you would like to redo the whole site definition.  So, small JavaScript enhancements and other client-side are typically a good way to achieve your customizations.

The Challenge

In this installment we received a request to allow users to reply to other users’ comments.  After searching the Internet for a few hours a few good solutions surfaced.   A very good solution was the Comment Box [Web Part] for SharePoint by Alexander Bautz (to link to Alexandar’s blog entry click here). 

This is a general comment web part that you can through on any SharePoint site and get comments with replies implemented completely in JavaScript. Problem Solved!  well, not so fast.   This is a great general web part that even takes care of creating the backend list of comments.

We already have a comment list integrated into the blog site. We already had a few dozen comments that we did not want to lose, so using a new list will require additional migration work.  Even without migration, this Comment list is deeply linked with the Posts list with totals posted on the site and we wanted to keep using it.

The Solution

Comment Box for SharePoint is so well written that I had no problems digging into the JavaScript and modifying it to work for the specific needs of the blog site (alas, loosing its more general nature in the process.)    I also created a a solution (gasp.  what about Office 365?! – it’s optional..) to allow our users to quickly change their blogs to have comments with replies.  This is a convenient way to replace the existing Comment Box and comment list with the new web parts as well as make a minor change to the existing Comments list on the blog.

The event receiver does the following tasks:

    1. Validates and then adds a “Parent” column to the Comments list
    2. Modifies the Post page to hide “Comments” and “New Comment” web parts
    3. Adds a Content Editor Web-part (CEWP) with pre-defined HTML to show draw “threaded” comments.

The comment box script was modified to use the existing (but modified) Comments list.  the main change from the original javascript was to modify the PostId Parent of the list and include it in the “Insert” statement.  The PostId is grabbed from the URL by the initial javascript and then is used to tie the comment to the Post list. 

Finally, the button styles for posting and replying to the comments were matched to the blog button style with the help of css and two small images.

The final code can be found here (click here to download the code.)

If you are on the SharePoint version of this blog ( you can see a live demo by posting a comment.

  1. I downloaded the folder “ThreadedComments” from the onedrive provided. Can you please describe how to deploy the contents to SharePoint? I didn’t see a solution file. Thanks!

    • bernoulli permalink

      That is an oversight. I posted the code – not the solution package. You will need a copy of Visual Studio Professional or better (2010 or later.) you can then compile and package the code to produce a package. Good luck!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: