Tuesday, October 25, 2011

Show User “I Like It” data in Webpart

Leave a Comment

"I like it" data is referred using Microsoft.Office.Server.SocialData Namespace.

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.Office.Server;
using Microsoft.Office.Server.SocialData;
using System.Text;
namespace ResearchProject.WebParts
{
    [ToolboxItemAttribute(false)]
    public class LikeWebpart : WebPart
    {
        protected override void CreateChildControls()
        {
            UserProfile profile = null;
            SPServiceContext serviceContext = SPServiceContext.Current;
            UserProfileManager profileManager = new UserProfileManager(serviceContext);

            profile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.RawSid);

            SocialTagManager socialmanager = new SocialTagManager(serviceContext);
            SocialTag[] tags = socialmanager.GetTags(profile);

            StringBuilder tagstring = new StringBuilder();
            foreach (SocialTag tag in tags)
            {
                if (tagstring.Length > 0)
                {
                    tagstring.Append(",");
                }
                tagstring.Append(tag.Title);
            }
            this.Controls.Add(new LiteralControl(tagstring.ToString()));
        }
    }
}

0 comments: