none
How to get the count of replies on a particular day for an item in the discussion board RRS feed

  • Question

  • How to get the count of replies on a particular day for an item in the discussion board using Camel Query 
    Monday, April 11, 2016 1:52 PM

Answers

  • Hi,

    To get the count of replies on a particular day for an item in the discussion board, please refer to the code demo below:

            static void Main(string[] args)
            {
    
                using (SPSite site = new SPSite("http://sitecollectionURL"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["YourListName"];
                        SPListItem item = list.GetItemById(13);//item ID
                        GetReplies(list, item);
                    }               
                }
            }
            private static void GetReplies(SPList list, SPListItem item)
            {
                SPQuery query = new SPQuery();
                query.Folder = item.Folder;            
                SPListItemCollection collection = list.GetItems(query);
                int count = 0;
                foreach (SPListItem reply in collection)
                {
                    var datetime=reply["Created"].ToString();              
                    var date = datetime.Split(null);
                    if (date[0] == "4/12/2016")
                    {
                        count++;
                    }
                }
                Console.WriteLine(count);           
            }
    

    About how to get the replies from discussion board:

    http://www.c-sharpcorner.com/UploadFile/40e97e/programmatically-read-discussion-board-replies/

    Best Regards,

    Victoria 


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Marked as answer by ghsajith Tuesday, April 12, 2016 1:50 PM
    Tuesday, April 12, 2016 10:40 AM
    Moderator

All replies

  • Hi,

    To get the count of replies on a particular day for an item in the discussion board, please refer to the code demo below:

            static void Main(string[] args)
            {
    
                using (SPSite site = new SPSite("http://sitecollectionURL"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists["YourListName"];
                        SPListItem item = list.GetItemById(13);//item ID
                        GetReplies(list, item);
                    }               
                }
            }
            private static void GetReplies(SPList list, SPListItem item)
            {
                SPQuery query = new SPQuery();
                query.Folder = item.Folder;            
                SPListItemCollection collection = list.GetItems(query);
                int count = 0;
                foreach (SPListItem reply in collection)
                {
                    var datetime=reply["Created"].ToString();              
                    var date = datetime.Split(null);
                    if (date[0] == "4/12/2016")
                    {
                        count++;
                    }
                }
                Console.WriteLine(count);           
            }
    

    About how to get the replies from discussion board:

    http://www.c-sharpcorner.com/UploadFile/40e97e/programmatically-read-discussion-board-replies/

    Best Regards,

    Victoria 


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Marked as answer by ghsajith Tuesday, April 12, 2016 1:50 PM
    Tuesday, April 12, 2016 10:40 AM
    Moderator
  • Thanks a lot
    Tuesday, April 12, 2016 1:50 PM