Get all comments
By Anatoly Mironov
If you try to get comments quantity for a url, you may wonder, why there is only quantity of the comments which the current user has posted:
public int GetNumberOfNewsPageComments
(SPSite currentSite, string pageUrl, int max)
{
var serviceContext =
SPServiceContext.GetContext(currentSite);
var socialCommentManager =
new SocialCommentManager(serviceContext);
var comments = socialCommentManager
.GetComments(new Uri(pageUrl), max);
if (comments != null)
{
return comments.Length;
}
return -1;
}
```The solution is to impersonate the SPSite object with an account who has the rights to manage social data. Give this permission to the account in CA - Application Management - Service Applications - User Profile Service. [![](https://sharepointkunskap.files.wordpress.com/2011/09/manage-social-data.png?w=284 "manage-social-data")](https://sharepointkunskap.files.wordpress.com/2011/09/manage-social-data.png)