In OOB tag cloud, we get tag cloud only by Current user or By All tags.
To Customize tag cloud by accountname or profile ,
1. Add the reference of /_layouts/1033/styles/socialdata.css in page layouts or masterpage.
2. Add dll reference C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\microsoft.sharepoint.portal.dll
3. In Visual studio, Right click solutionAdd service reference click on ‘Advanced’ buttonAdd web referenceclick link Web services on local machine.
4. Search for socialdataservice.asmx.
public class TagWP : WebPart
{
localhost.SocialTermDetail[] details;
localhost.SocialDataService objSocialDataService = null;
long tagCount = 0;
protected override void CreateChildControls()
{
objSocialDataService = new localhost.SocialDataService();
int maximuItems=10;
int intstartIndex=1;
objSocialDataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
string accountname= SPHttpUtility.HtmlEncode(Context.Request.QueryString["accountname"]);
details = objSocialDataService.GetTagTermsOfUser(accountname, maximuItems);
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
writer.Write("DIV id='tagCloudDatatagCloudByProfile' class='ms-TagCloud ms-TagCloudLink
");
writer.Write("DIV id='tagCloudByProfile'
");
SPSite oSiteCollection = SPContext.Current.Site;
string hostname = oSiteCollection.HostName;
foreach (SocialTermDetail tag in details)
{
string tagurl = "http://" + hostname + "/my/tagprofile.aspx?termid=" + tag.Term.Id.ToString();
SocialUrlDetail [] urls = objSocialDataService.GetAllTagUrls(tag.Term.Id);
tagCount = urls.LongLength != 0 ? urls.LongLength : 1;
writer.Write("A class='rank" + tagCount.ToString() +"' href=" + tagurl + ">" + tag.Term.Name + "/A> /SPAN>");
}
writer.Write("/DIV>");
writer.Write("/DIV>");
}
Download Source Code
string hostname = oSiteCollection.HostName;
foreach (SocialTermDetail tag in details)
{
string tagurl = "http://" + hostname + "/my/tagprofile.aspx?termid=" + tag.Term.Id.ToString();
SocialUrlDetail [] urls = objSocialDataService.GetAllTagUrls(tag.Term.Id);
tagCount = urls.LongLength != 0 ? urls.LongLength : 1;
writer.Write("A class='rank" + tagCount.ToString() +"' href=" + tagurl + ">" + tag.Term.Name + "/A> /SPAN>");
}
writer.Write("/DIV>");
writer.Write("/DIV>");
}
Download Source Code
No comments:
Post a Comment