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

Forums / Developing with Sitefinity / How to get Latest comment date of each blog?

How to get Latest comment date of each blog?

4 posts, 0 answered
  1. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    29 Jan 2010
    Link to this post
    Hi All,

    I am facing a problem that is i have the sitefinity control for displaying blogs List and here i got the comments count easily but now there is a requirement that i have to show the Latest comment date , but i cant figure out that where to get the comments or if i can some how get the blog ID From this repeater.

    Your help would be really appreciated.

    Thanks
    Regards
    Adeel Arif.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    29 Jan 2010
    Link to this post
    Hi Adeel Arif,

    IComment object has a function getCreationDate(); that will allow you to show the creation date. You can sort the list of comments and get the latest one.

    If you want to display the latest created comment of the Master mode of a ContentView based control you have to create a custom class that ionherits from the ContentView based control, map the templates, add label to the master template that will show the latest comment name and date or whatever you want.
    In you custom class override SetItemContent where you have access to the id of each content item by using "contentItem" parameter of the method. This will allow you to get the comments for your content item object.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Adeel Arif
    Adeel Arif avatar
    27 posts
    Registered:
    30 Dec 2009
    02 Feb 2010
    Link to this post
    Hi Ivan,

    Thanks for your detailed reply but it seems my expertise are not that much , it would be really kind of you if you could just give me a small example i would really be much thankful.

    Regards
    Adeel Arif.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    02 Feb 2010
    Link to this post
    Hi Adeel Arif,

    This line will return all comments sorted in descending order of their creation date.

    IList commentsList = ContentManager.Providers["Blogs"].GetComments(new Guid("4FCECC6E-CE2B-4A87-9006-0CC0C6ECAE06"), true, "DateCreated DESC");

    To show the latest comment date you need to create a custom control that inherits from blog posts and add a new label which text is the last post creation date.

    IComment last = commentsList[0] as IComment;
    DateTime dt = last.GetCreationDate();
    Label lb = new Label();
    lb.Text = dt.Date.ToLongDateString();
    Controls.Add(lb);


    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered