Alert This post is over a year old, some of this information may be out of date.

Take your SharePoint social features to the next level with “I like it” and “Tags” counters: Part 4

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.

Show image Blog with social features
Blog with social features

First of all the reason why it is happening.

Reason

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.

Show image Posts Query
Posts Query

Normally it should return the following items:

Show image Blog post tags
Blog post tags

When I did a query for all the tags from a specific user, I noticed something interesting:

Show image ViewPost Reference
ViewPost Reference

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.

Solution

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
// 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
  if (!string.IsNullOrEmpty(root))
  {
    if (uri.AbsoluteUri.Contains(root))
    {
      uri = new Uri(SPContext.Current.Web.Url);
    }
  }
}
else
{
  uri = new Uri(uri.AbsoluteUri.Replace("Post.aspx", "ViewPost.aspx"));
}

Here you can find the whole code:

SocialFeatures Code

Result

Show image Blog post tags end result
Blog post tags end result

Comments

Back to top