Extending the SocialCommentControl

April 6 2011 163 comments

SocialCommentControl is the control, which enables commenting on a page. You can use social commenting feature with the Note Board web part (Social Collaboration > Note Board) by adding the web part onto your page. You would have to have User Profile Service Application provisioned to enable social comments. Comments are stored in the Social DB (SocialComments table) of your Service Application.

What we did recently was that we extended the out-of-box SocialCommentControl to be included in a custom page layout with a custom content type. The content type contains a boolean field to indicate, if commenting would be enabled on the published page. Another thing is that we can catch the events when a new comment is added, deleted or updated and build our own custom functionality, if needed, to handle those events.

The first thing was to take a look at the SocialCommentControl class with reflector in Microsoft.SharePoint.Portal assembly. The control inherits from System.Web.UI.WebControls.WebControl and implements the System.Web.UI.WebControls.ICallbackEventHandler. The event handling for comments takes place in RaiseCallBackEvent and the code can be dug out with reflector.

So what if there was a case where the editor wants to specify if commenting is allowed on a published page and wants to get the added comments via email if commenting would be enabled to the page. The scenario is not from our business case and is purely hypothetical but as a demo the case will do just fine.

Below is a quick demonstration of how to handle enabling commenting on a page and get the editor of the page to receive email every time a comment is either added or edited. The sample contains also a workaround for the inconvenient behavior of the out-of-box SocialCommentControl which breaks the DOM and makes web designers mumble when they come across the fact that one div is unclosed.

public class SocialComments : SocialCommentControl, ICallbackEventHandler
    public SocialComments()
        Load += SocialComments_Load;
    protected void SocialComments_Load(object sender, EventArgs e)
        var item = SPContext.Current.ListItem;
        // check if the current page has commenting allowed
        var allowComments = (item["AllowComments"] != null &&
            (bool)(item["AllowComments"])) ? true : false;
        if (!allowComments)
            Visible = false;

    protected override void CreateChildControls()
        // the DOM is a terrible thing to break
        // http://www.sharepointblues.com/2010/09/28/fix-disabled-page-scrolling-on-navigation-settings/
        Controls.Add(new LiteralControl("</div>"));

    public string GetCallbackResult()
        return base.GetCallbackResult();

    public void RaiseCallbackEvent(string eventArgument)

            var item = SPContext.Current.ListItem;
            var page = PublishingPage.GetPublishingPage(item);
            var editorEmail = page.CreatedBy.Email;
            var url = SPContext.Current.Web.Url + "/" + item.Url;
            var currentUser = SPContext.Current.Web.CurrentUser.Name;

            var document = new XmlDocument();
            var documentElement = document.DocumentElement;

            eventArgument when added:
            <Item  type='Add'>
                <RTEContents>This is a new comment</RTEContents>

            eventArgument when edited
            <Item type='Edit'
            CurrentPage='1' >
            <RTEContents>This is an&amp;#160;edited comment</RTEContents>

            if (documentElement != null)
                var event = documentElement.GetAttribute("type");
                if (event != "Get")
                    if (event == "Add" || event == "Edit")
                        var contentElement =
                        var content =
                        var subject =
                        string.Format("Comment event '{0}' at {1}",
                        event, DateTime.Now);
                        var message =
                        {0}<br/><br/>By {1}<br/><br/>Url: {2}"
                        content, currentUser, url);
                        SPUtility.SendEmail(SPContext.Current.Web, true,
                            false, editorEmail, subject, message);
        catch(Exception ex)
            // log the exception

Below is the email the editor would get when a new comment is added to the page where commenting is enabled and the custom extension of the SocialCommentControl is included.

Popularity: 11% [?]

163 comments to “Extending the SocialCommentControl”

  1. Hi there! This iss kind of off topic but I nneed
    some help from an established blog. Is it very hard to set up
    your own blog? I’m not very techincal but
    I can figure things out pretty quick. I’m thinking about making my own but I’m not
    sure where to begin. Do you have any tips or suggestions?


    Feel free to surf to my blog: coupon Codes App

  2. Trèѕ bon poste, perfsistez comme ça

    Look into my weƅb page film de baise

  3. Manuela says:

    Today, I went to the beachfront with my children.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is
    entirely off topic but I had to tell someone!

    Also visit my web page; save the last dance (Manuela)

  4. Je suis venu sur ce site web pɑr hasard et puis
    je ne le regrette pas !

    my homepage … alexis silver

  5. Hey There. I found your blog using msn. This is an extremely well written article.
    I will make sure to bookmark it and come back to read more of your
    useful info. Thanks for the post. I will certainly comeback.

  6. I have fun with, result in I discovered just what I
    used to be having a look for. You have ended my four day long hunt!
    God Bless you man. Have a nice day. Bye

  7. I go to see every day some websites and information sites to read articles, but this website provides feature
    based writing.

  8. My brother suggested I might like this web site. He was entirely right.

    This post truly made my day. You cann’t imagine just how much time I had spent for this information! Thanks!

  9. Pretty section of content. I just stumbled upon your web site and
    in accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Any way I will be subscribing to your feeds and even I achievement you access consistently fast.

  10. Magnificent web site. A lot of useful info here. I am sending it to a few buddies ans also sharing in delicious.
    And certainly, thanks for your sweat!

  11. I am really happy to read this website posts which contains tons of valuable facts, thanks for providing such

  12. My partner and I absolutely love your blog and find the majority of your post’s to be
    what precisely I’m looking for. Would you offer guest writers to write content to suit your needs?

    I wouldn’t mind writing a post or elaborating on most of the subjects you write regarding here.
    Again, awesome web log!

  13. hymen says:

    You could certainly see your enthusiasm within the article you write.

    The arena hopes for more passionate writers like you who aren’t afraid to mention how they believe.
    Always go after your heart.

  14. female hymen says:

    Wow that was unusual. I just wrote an very long comment but after
    I clicked submit my comment didn’t show up. Grrrr… well
    I’m not writing all that over again. Anyhow, just wanted to say
    wonderful blog!

  15. Every weekend i used to pay a visit this site, because i want enjoyment,
    for the reason that this this web page conations really pleasant funny information too.

  16. hymen photo says:

    Incredible story there. What happened after?
    Good luck!

  17. hymen says:

    You should be a part of a contest for one of the highest quality
    blogs on the web. I am going to highly recommend this

  18. hymen? says:

    Hello I am so glad I found your webpage, I really found you by
    mistake, while I was searching on Yahoo for something else,
    Nonetheless I am here now and would just like to say thank you for
    a marvelous post and a all round interesting blog (I also love the theme/design), I don’t have time to go
    through it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time I will be back to
    read a great deal more, Please do keep up the great work.

  19. A fascinating discussion is definitely worth
    comment. I do believe that you should write more on this subject matter,
    it may not be a taboo subject but typically people don’t discuss these topics.
    To the next! Best wishes!!

  20. hymen says:

    Wonderful site you have here but I was curious if you knew of any community forums that cover the same topics talked
    about here? I’d really like to be a part of group where I can get comments from other experienced people that
    share the same interest. If you have any recommendations, please let me know.

  21. Rosemarie says:

    While that kind of physical exercise will certain help the blood flow to the brain, physical activity, or doing more of what you are already
    doing, like walking, will increase blood flow to the brain in the earlier stages of treatment for drug addiction.

  22. domain says:

    You really make it appear so easy with your presentation however I find this topic to be actually one thing that I think I would by no means understand.
    It kind of feels too complicated and extremely wide for me.
    I’m taking a look ahead to your next post, I’ll attempt to get
    the cling of it!

  23. sexe amateur says:

    On va ѵous dire que ce n’est pas faux !!!

    Have a lߋoҟ att my website: sexe amateur

  24. After looking into a handful of the articles on your site, I truly appreciate your technique of writing a blog.
    I saved as a favorite it to my bookmark site list and
    will be checking back in the near future.
    Please visit my web site as well and let me know what
    you think.

  25. francesco says:

    Great article!
    Thank you

  26. Asley says:

    Great beat ! I wish to apprentice at the same time as you amend your
    site, how can i subscribe for a weblog site? The
    account aided me a applicable deal. I were a little bit
    familiar of this your broadcast offered brilliant transparent idea

  27. David Trover says:

    Nice post man. I learn something new everyday. It is always interesting to read contents from other writers like yourself. Thanks for sharing. Hosting Company Find Hostwinds Reviews

  28. The units discussed remain currently performing OK after initial installment, five years in 2014.|Even though the units are 26
    You should fix the vinyl flooring joints when you observe it is currently coming off.

  29. Home of the finest chrome houses on earth to one, Buenos
    Aires, Teatro Colon, is a location that’s undoubtedly worth
    a trip.

  30. If yօu want to get a good deal from this article then yߋu have to applƴ such
    strateɡies to your won web site.

  31. I hire a room in a house (I guess what the English might call a bedsit),
    so my feng shui chances are even thinner than in an house.||Getting into my first residence this summer, which listing definitely helps.

  32. I am moving from the beginning of Sept into my first residence and I am both enthusiastic and tense.

  33. These audio films get their plain strangeness from a
    number of places.

  34. Mantenga la mayor y mejor seguridad en su casa, sin permitirle a los ladrones ingresar al sitio que debe suponer es el más seguro, su casa.

  35. Delilah says:

    Otro consejo ya antes de entrar de lleno en la dieta que te ayudará a perder 10 kilogramos en un mes.

  36. Doug says:

    En el centro de Control y Prevención ha registrado que entre
    el tres por ciento y el siete por ciento
    de pequeños en edad escolar en los E.U. tienen TDAH.

  37. Τhis is a topic that is near to my heart… Many thanks!
    Exaϲtly where are үour contact details thοuɡh?

  38. It’s trulƴ very complex in this busƴ life to listen news
    on TV, thus І only use world wide web fοr that reason, and get
    the most up-to-date news.

  39. David Hyde says:

    Αfter I originally commented I appear to have clicked on the -Notify me when new comments are added- checkbox and
    from now on wheneѵеr a comment is added I reϲieve four emailѕ
    ѡith the same comment. There haѕ to be an easy method you arе
    able to remove me from that service? Many thanks!

  40. Tracy says:

    -Jeremiah Grossman, founder and CEO of White Hat Security suggests
    using different browsers for separate activities.

    For our example, that means they have to also be in your village and
    close to the ferry’s route. There are simple ways to avoid having your marketing accounts broken into.

  41. I like the helpful info you provide for your articles.
    I’ll bookmark your blog and take a look at again here frequently.
    I am relatively sure I will be informed many new stuff proper right here!
    Best of luck for the next!

  42. Newton says:

    This does not imply you have to break the bank with
    wedding event DJ prices, but see exactly what alternatives are actually
    worth the expense.

  43. Thanks for finally talking about > Extending the SocialCommentControl
    | SharePoint Blues < Liked it!

    my blog post; trucking
    maintenance software

  44. Berniece says:

    Howdy! Isimply wish to offer you a big thumbs up for the excellent information you’ve got here
    on this post. I am returning to your website for more soon.

  45. soccer news says:

    Wonderful information, Thanks.

  46. Yes! Finally someone writes about mua căn hộ vinhomes gardenia.

  47. Extending the SocialCommentControl | SharePoint Blues
    roger vivier sale http://www.snehabhavanktm.org/images/vivier.htm

  48. art says:


  49. My brother is a nurse and he takes the night shifts in the carido ward because he loves the down time, he does nothing Most nights and it gives him experience at being the charge

  50. With havin so much content and articles do you ever run into any problems of plagorism or
    copyright infringement? My blog has a lot of exclusive content I’ve either authored myself or outsourced but it appears a lot of it is popping it up all over
    the web without my permission. Do you know any methods to help reduce content from
    being ripped off? I’d truly appreciate it.

Leave a Reply