Creating Social Comments using c#:
using (SPSite site = new SPSite("http://contoso"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);
mySocialCommentManager.AddComment(new Uri("My URL"), “My Comment”);
}
Retrieving Social Comments using c#:
public class PageComments
{
public string Comment { get; set; }
public UserProfile CommentOwner { get; set; }
public DateTime CommentDate { get; set; }
}
public class GetCommentsClass
{
public PageComments GetCommentsByPage(SPListItem item,int prevDates)
{
PageComments pc = new PageComments();
SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);
SocialComment[] comments = mySocialCommentManager.GetComments(new Uri(Site + "/" + item.File.Url));
foreach (SocialComment comment in comments)
{
if (comment.LastModifiedTime.ToLocalTime().CompareTo(DateTime.Now.AddDays(previousDates)) >= 0)
{
pc.Comment = comment.Comment;
pc.CommentDate = comment.LastModifiedTime;
pc.CommentOwner = comment.Owner;
}
}
return pc;
}
}
No comments:
Post a Comment