Retrieve and add comments to a noteboard webpart


  • Hi i have a web part page where i added a note board webpart.


    I am trying to add a new comment to the note board and to retrieve existing comments using the following  code from  an application page


    <%@ Assembly Name="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    <%@ Assembly Name="Microsoft.Office.Server, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

    <%@ Assembly Name="Microsoft.Office.Server.UserProfiles, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


    <%@ Import Namespace="Microsoft.SharePoint" %>

    <%@ Import Namespace="Microsoft.Office.Server.SocialData" %>

    <script runat="server" language="C#">


    protected void Page_Load(object sender, EventArgs e)


       Uri myUri = new Uri("http://srvintranetapps/ff/paginas/home.aspx");



         using (SPSite site = new SPSite("http://srvintranetapps"))




            SPContext.Current.Web.AllowUnsafeUpdates = true;

            SPServiceContext context = SPServiceContext.GetContext(site);

            SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);


            //retrieve comments

                    SocialComment[] comments = mySocialCommentManager.GetComments(myUri);

                    foreach (SocialComment comment in comments)


                       Response.Write("--" + comment.Url + ": " + comment.Comment + "<br>");



                    //Add Coment

                    mySocialCommentManager.AddComment(myUri, "comment text");



         catch(System.Exception ex)






                    SPContext.Current.Web.AllowUnsafeUpdates = false;







    The code works but I don’t see the new comments inserted on the note board webpart in the web part page and I can´t also retrieve the comments that are displayed in the noteboard

    Can anyone help


    Thanks in advance


    Telmo Cruz

    Tuesday, November 16, 2010 1:36 PM