Skip to content

Instantly share code, notes, and snippets.

@vgrem
Last active December 17, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/5566771 to your computer and use it in GitHub Desktop.
Save vgrem/5566771 to your computer and use it in GitHub Desktop.
ontent By Query web part with social capabilities
/// <summary>
/// Adding social comments to the results of Content Query web part
/// </summary>
[ToolboxItem(false)]
public class SocialCBQ : ContentByQueryWebPart
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.ProcessDataDelegate = ProcessSocialData;
}
private DataTable ProcessSocialData(DataTable data)
{
var context = SPServiceContext.GetContext(SPContext.Current.Site);
scm = new SocialCommentManager(context);
data.Columns.Add("PageUrl", typeof(string));
data.Columns.Add("PageComments", typeof(int));
foreach (DataRow row in data.Rows)
{
var fileRefVal = new SPFieldLookupValue((string)row[SPBuiltInFieldId.FileRef.ToString("B")]);
string pageUrl = SPContext.Current.Site.MakeFullUrl("/" + fileRefVal.LookupValue);
var pageComments = scm.GetCount(new Uri(pageUrl));
row["PageUrl"] = pageUrl;
row["PageComments"] = pageComments;
}
return data;
}
private SocialCommentManager scm;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment