//using Microsoft.Office.Server.SocialData; - include this for SocialCommentManager
// Variable declaration
private SocialCommentManager _commentManager = null;
private Uri _currentUri = null;
_siteId = SPContext.Current.Site.ID;
_webId = SPContext.Current.Web.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(_siteId))
{
using (SPWeb web = site.OpenWeb(_webId))
{
_url = HttpContext.Current.Request.Url.ToString();
//Create Service Context
SPServiceContext _serviceContext =
SPServiceContext.GetContext(web.Site);
if (!string.IsNullOrEmpty(_url))
{
_currentUri = new Uri(_url);
//Initialize SocialCommentManager
_commentManager = new
SocialCommentManager(_serviceContext);
if (_currentUri != null)
{
_totalComments =
_commentManager.GetCount(_currentUri);
}
}
}
}
});This code snippet explains how to get the number of comments for current URL using server side object model, using SocialCommentManager class.
