I have a SocialCommentControl in my PageLayout.
In my pageload there is a method to get the counts.
protected void Page_Load(object sender, EventArgs e)
{
GetSocialCommentCount();
}
In the method,
public void GetSocialCommentCount()
{
SPWeb web = SPContext.Current.Web;
int id = Convert.ToInt32(this.ID.ItemFieldValue);
SPList list = web.Lists.TryGetList("ListList");
SPListItem item = list.GetItemById(id);
string webUrl = web.Url;
string dispUrl = item.ContentType.DisplayFormUrl;
if (dispUrl == "")
dispUrl = list.Forms[PAGETYPE.PAGE_DISPLAYFORM].Url;
bool isLayouts = dispUrl.StartsWith("_layouts/", StringComparison.CurrentCultureIgnoreCase);
dispUrl = String.Format("{0}/{1}?ID={2}", webUrl, dispUrl, item.ID);
if (isLayouts)
dispUrl = String.Format("{0}&List={1}", dispUrl, SPEncode.UrlEncode(list.ID + ""));
SocialCommentManager scm = new SocialCommentManager();
Uri currUri = new Uri(dispUrl);
var count = scm.GetCount(currUri);
lblNumComments.Text = count + " comments";
}
However the counts do not reflect correctly for the specific item. I have checked and the Uri correctly points to the selected view item. Does anybody have a clue?