Getting number of comments from server object model using SocialCommentManager class

  1. //using Microsoft.Office.Server.SocialData; - include this for SocialCommentManager

  2. // Variable declaration   
  3.   
  4. private SocialCommentManager _commentManager = null;  
  5. private Uri _currentUri = null;  
  6.   
  7. _siteId = SPContext.Current.Site.ID;  
  8. _webId = SPContext.Current.Web.ID;  
  9.   
  10. SPSecurity.RunWithElevatedPrivileges(delegate()  
  11.    {  
  12.         using (SPSite site = new SPSite(_siteId))  
  13.           {  
  14.                using (SPWeb web = site.OpenWeb(_webId))  
  15.                 {  
  16.                     _url = HttpContext.Current.Request.Url.ToString();  
  17.                      //Create Service Context  
  18.                       SPServiceContext _serviceContext =    
  19.                                  SPServiceContext.GetContext(web.Site);  
  20.                       if (!string.IsNullOrEmpty(_url))  
  21.                          {  
  22.                                 _currentUri = new Uri(_url);  
  23.                                 //Initialize SocialCommentManager  
  24.                                 _commentManager = new   
  25.                                   SocialCommentManager(_serviceContext);  
  26.                                 if (_currentUri != null)  
  27.                                 {  
  28.                                     _totalComments =   
  29.                                        _commentManager.GetCount(_currentUri);  
  30.                                 }  
  31.                          }  
  32.                 }  
  33.           }  
  34.      });