+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Testing blog comment publish status

Testing blog comment publish status

2 posts, 0 answered
  1. Ben Wright
    Ben Wright avatar
    2 posts
    Registered:
    06 Apr 2006
    13 Oct 2010
    Link to this post

    I am using SiteFinity 3.7 SP2. I am getting a list of blog post comments. I want to filter out the comments that are not published. How do I go about doing this? As usual, I can't anything beyond the basics in the documentation... Below is the pertinent code:

     

    var

     

     

    listofComments = from blogs in listOfBlogs.OfType<IBlog>()

     

     

     

    from blogposts in blogs.Posts.OfType<IContent>()

     

     

     

    from comments in blogposts.Comments.OfType<IComment>()

     

     

     

    orderby comments.Parent.DateCreated descending

     

     

     

    select new {

     

    comment = comments,

    blogpage = blogs.BlogPage

    };

     

     

     

    if (listofComments.Any()) {

     

     

     

        IComment commentItem = default(IComment);

     

     

     

        for (int idx = 0; idx <= Math.Min(mCommentCount - 1, listofComments.Count() - 1); idx++) {

     

            commentItem = listofComments.ElementAt(idx).comment;

     

     

            output.Append(

     

    "<a href=\"" + GetUrl(listofComments.ElementAt(idx).blogpage.Replace
                (
    ".aspx", "/") + commentItem.Parent.UrlWithExtension) + "\">");

     

            output.Append(commentItem.Text.Substring(0,(mMaxCommentTextLength == 0 ? 
                commentItem.Text.Length :

     

    Math.Min(mMaxCommentTextLength, 
                commentItem.Text.Length))) +
    "..." + "</span>");

     

            output.Append(

     

    "</a>");

     

            ...
        }
    }

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Oct 2010
    Link to this post
    Hi Ben,

    The IComment object does not have a status like Published -NotPublished. There are visible and not visible comments. You can filter comments by their visibility by using this code

    // contentItem is the IContent object  - your blog post
    var listofComments = contentItem.Comments.Cast<IComment>().ToList().Where(c => c.Visible = false);

    You can use GetComments method of ContentManager class to get a list of all comments per provider. The method has 7 overloads which allows you to get posts by content ID, filter, sort them etc.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered