My intention was to write three blog posts on this topic, but a commenter told me that a problem arises with blog post items. The counters always return zero.
In this part I will show you why this is happening and what you could do to solve this.
First of all the reason why it is happening.
A standard blog post URL in SharePoint looks like this: http://sp2010/Lists/Posts/Post.aspx?ID=1.
Using this URL on the Manage Social Tags and Notes page of my user profile service, it did not return any results.
Normally it should return the following items:
When I did a query for all the tags from a specific user, I noticed something interesting:
The tags are not linked to the Post.aspx page, but to the ViewPost.aspx page: http://sp2010/Lists/Posts/ViewPost.aspx?ID=1.
When I checked the URL of the Social Data Frame, I saw that it also used the ViewPost.aspx page as reference.
The solution is very simple, you only need to replace the Post.aspx from the URL path with ViewPost.aspx.
Here is the code to do this:
// Get page URL
Uri uri = this.Page.Request.Url;
// Check if it is a blog post
if (-1 == uri.AbsoluteUri.IndexOf("post.aspx", StringComparison.OrdinalIgnoreCase))
// Check if page is welcome page
string root = web.RootFolder.WelcomePage;
// Check if welcome page is not empty
uri = new Uri(SPContext.Current.Web.Url);
uri = new Uri(uri.AbsoluteUri.Replace("Post.aspx", "ViewPost.aspx"));
Here you can find the whole code: