Comments For Blogs
Hello Admin,
I am using following query to Retrive Commnet for given Post
1 - IQueryable
<Comment> comments = manager.GetComments().Where(t => t.CommentedItemID == allPosts.Id);
2 - List<Guid> ilistGuid = new List<Guid> guid ;
IQueryable<Comment> postToLocate = manager.GetComments();
postToLocate.Where(p => p.CommentedItemID.Equals(allPosts.Id));
1- Query returning me following error
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. and the Error Attached
2- Second Query returning me all the Comments though i have Specified
p => p.CommentedItemID.Equals(allPosts.Id)
Please tel me the Solution
Thanks & Regards
Anu.
Hello Anu,
Could you try to expose the ID which you use to filter the items as a local variable or pass it as a string into the expression?
Greetings,
Ivan Dimitrov
the Telerik team
Helloo Admin,
1) I tried with following
IQueryable<Comment> comments = manager.GetComments().Where(t => t.CommentedItemID == new Guid("5939c218-8f71-4f07-be00-950627bc122c"));
IQueryable<Comment> postToLocate = manager.GetComments()
.Where(p => p.ParentGroupIds.Contains(
new Guid("5939c218-8f71-4f07-be00-950627bc122c")));
protected void ItemsList_ItemDataBound(object sender, ListViewItemEventArgs e)
if (e.Item.ItemType == ListViewItemType.DataItem)
ListViewDataItem ldr = (ListViewDataItem)e.Item;
--- Over here below value im getting 0
((Telerik.Sitefinity.GenericContent.Model.Content)(ldr.DataItem)).Comments.Count
BlogsManager
manager = BlogsManager.GetManager();
var allPosts = manager.GetBlogPosts()
.Where(s => s.Status == ContentLifecycleStatus.Live);
var sortedPost =
from p in allPosts
orderby p.PublicationDate descending
select p;
Please Help ... where im getting wrong ?
Thanks & Regards
Anu.
Hi Anu,
Why you cast the data item which should be a BlogItem to Telerik.Sitefinity.GenericContent.Model.Content instead of the blog model?
Regards,
Ivan Dimitrov
the Telerik team
Hello Ivan,
I thought using ((Telerik.Sitefinity.GenericContent.Model.Content)(ldr.DataItem)).Comments this will return me the number of comments for each post ...
Can u tel me the way of retrving the Comment for each Post ( Same as BlogPost Control of Sitefinity Which displays 'Go Comment' Or 'No Of Comment' )
Thanks & Regards ...
Hi Anu,
Please consider the code shown below
var posts = App.WorkWith().BlogPosts().Get();
// user where clause if you want to get posts froma a given parent
if
(posts.Count() > 0)
var listofAllComments =
new
List<Comment>();
// this is a list that will collect all comments
foreach
(BlogPost post
in
posts)
if
(post.Comments.Count > 0)
var commentsForSinglePost = post.Comments;
foreach
(Comment c
in
commentsForSinglePost)
listofAllComments.Add(c);
Hello Ivan,
I tried ur code still im getting Comment Count as 0
i m using SItefinitis following method to Insert Comment for gievn Blog Post
BlogPost
allPosts = manager.GetBlogPost(guid);
//Create a comment item
Comment comment = manager.CreateComment(allPosts);
//Set the comments properties
comment.Content = content;
comment.AuthorName = author_name;
comment.Website = website;
comment.Email = email;
comment.IpAddress = ip_address;
comment.CommentStatus =
CommentStatus.Hidden;
//save the changes
manager.SaveChanges();
I found tht this method dosent Insert values in 'sf_blog_posts_sf_commnt' Table ... coz of tht im getting Comment Count as 0 ...
Is ther any Solution for this ?
Thanks & Regards
Anu.
Hello Ivan,
I just Inserted Comment for 1 Post using SItefinity Default 'BlogPost' Template ( Drag n Drop tht control on page ) and then i Published tht Comment.
After tht i tried to retrive the same using
var posts = App.WorkWith().BlogPosts().Get();
// user where clause if you want to get posts froma a given parent
if
(posts.Count() > 0)
var listofAllComments =
new
List<Comment>();
// this is a list that will collect all comments
foreach
(BlogPost post
in
posts)
if
(post.Comments.Count > 0)
var commentsForSinglePost = post.Comments;
foreach
(Comment c
in
commentsForSinglePost)
listofAllComments.Add(c);
Hello Shailendra,
Most probably you have not assigned the comment to the blog post (with status Live) . I am sending you sample code that illustrates how to get the first blog post and crate comment for it. Then get the comment for this post.
var manager = BlogsManager.GetManager();
var firstpost = manager.GetBlogPosts().Where(myb => myb.Status == ContentLifecycleStatus.Live).First();
var comment = manager.CreateComment(firstpost);
comment.AuthorName =
"test111"
;
comment.Content =
"test111"
;
comment.Email =
"test11@sa.ss"
;
comment.Website =
"http://www.telerik.com"
;
comment.DateCreated = DateTime.UtcNow;
comment.IpAddress =
"127.0.0.1"
;
firstpost.Comments.Add(comment);
manager.SaveChanges();
var facade = App.WorkWith().BlogPosts();
var posts = facade.Get();
// user where clause if you want to get posts froma a given parent
if
(posts.Count() > 0)
var listofAllComments =
new
List<Comment>();
foreach
(BlogPost post
in
posts)
if
(post.Comments.Count > 0)
var commentsForSinglePost = post.Comments;
foreach
(Comment c
in
commentsForSinglePost)
listofAllComments.Add(c);
How to get the blogpost.Comment Count in widget template?
Blog posts >> edit >> List Setting >> myTemplate >> edit
Comments: <%# Eval("Comments.Count")%> returning 0 (zero) for a blogpost with comment of count 2
Hello Jingyuan,
Use <sf:CommentsBox ID="itemCommentsLink" runat="server" CssClass="sfpostCommentsCount"/> which by default display link to the comments. IF you want to display the comments just as text without link add enabled="false".
Regards,
Stanislav Velikov
the Telerik team
Thank you, Stanislav.
Hi Stanislav.
or any Admin,
Regarding <sf:CommentsBox ID="itemCommentsLink" runat="server" CssClass="sfpostCommentsCount"/>
how to show "0 comment" instead of "Go comment" when the comment for post is ZERO?
Hi Jingyuan,
Add HyperLinkNoCommentsText property to CommentsBox
<sf:CommentsBox ID="itemCommentsLink" runat="server" HyperLinkNoCommentsText="0" />
Greetings,
Stanislav Velikov
the Telerik team