locked
Retrieve and add comments to a noteboard webpart RRS feed

  • 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

  • Hi TelmoC,

     

    Thanks for your post.

     

    Here is the summary issue as I understand.

    Scenario: There are two web parts in the page. one is “Note Board” web part, and the other is a custom web part. When you try to add new comment to the note board web part, the custom web part can’t show the message at once.

     

    I think the problem is related to the mechanism of “Note Board” web part. I have  replied another thread, you can read it here : http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/ee48d898-ec39-420c-9820-49d3c667049c

     

    So I think you have to refresh the page to show the new comments in the custom web part.  Or you can make the page autorefresh at a center time, for example: two minutes.

    <meta http-equiv="refresh" content="120;url=your page">

     

    More information:

    http://en.wikipedia.org/wiki/Meta_refresh


    SharePoint 2010
    Thursday, November 18, 2010 3:50 AM