none
Retrieve and add comments to a noteboard webpart

    Question

  • 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=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

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

    <%@ Assembly Name="Microsoft.Office.Server.UserProfiles, Version=14.0.0.0, 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");

       SPSecurity.RunWithElevatedPrivileges(delegate()

       {

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

         {

         try

         {

            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");

                    Response.Write("Done");

         }

         catch(System.Exception ex)

         {

           Response.Write(ex.Message);

         }

         finally

         {

                    SPContext.Current.Web.AllowUnsafeUpdates = false;

         }

       }

       });

    }

    </script>

     

    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


    TC
    Tuesday, November 16, 2010 1:36 PM

Answers