{"id":6050,"date":"2020-03-17T10:11:34","date_gmt":"2020-03-17T10:11:34","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6050"},"modified":"2020-03-17T10:11:34","modified_gmt":"2020-03-17T10:11:34","slug":"retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/","title":{"rendered":"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM"},"content":{"rendered":"\n<p>In this\nblog, we are going to retrieve all topics including replies and their authors\nvalues of a discussion list .<\/p>\n\n\n\n<p>Below image shows a discussion list having&nbsp; topic and its replies from different authors . In our blog we will see how to retrieve it using CSOM programmatically.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/03\/1-1-1024x603.png\" alt=\"\" class=\"wp-image-6051\"\/><\/figure><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\nusing Microsoft.SharePoint.Client;\nusing System.Security;\n\nnamespace DiscussionList\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            ClientContext ctx = new \n   ClientContext(\"https:\/\/portal.sharepoint.com\/sites\/testsite\");\n            string password = \"Password\";\n            SecureString secureString = new SecureString();\n\n\n            foreach (char c in password.ToCharArray())\n            {\n              secureString.AppendChar(c);\n            }\n            ctx.Credentials = new \n       SharePointOnlineCredentials(\"user@domain.onmicrosoft.com\", secureString);\n\n           List list = ctx.Web.Lists.GetByTitle(\"Discussion List\");\n           ctx.Load(list);\n           ctx.ExecuteQuery();\n\n           ListItem topic = null;\n\n           ListItem discussionReply = null;\n           CamlQuery query = CamlQuery.CreateAllFoldersQuery();\n           ListItemCollection topics = list.GetItems(query);\n           ctx.Load(topics);\n           ctx.ExecuteQuery();\n\n        if (topics != null &amp;&amp; topics.Count > 0)\n        {\n            for (int iItemCount = 0; iItemCount &lt; topics.Count; iItemCount++)\n            {\n                topic = topics[iItemCount];\n                query = CamlQuery.CreateAllItemsQuery(100, \"Title\", \"ID\", \"Body\", \"Author\", \"MyAuthor\", \"MyEditor\", \"Modified\", \"Created\");  \/\/ add the properties that you want to retrieve\n\n                query.FolderServerRelativeUrl = topic[\"FileRef\"].ToString();\n\n                ListItemCollection repliesColl = list.GetItems(query);\n                ctx.Load(repliesColl);\n                ctx.ExecuteQuery();\n\n                if (repliesColl == null)\n                    repliesColl = GetAllRepliesFromSpecificTopic(topic.Id.ToString(), list, ctx);\n\n                Console.WriteLine(\"Topic Content : \" + topic[\"Body\"] + \"\\n\");\n\n\n                if (repliesColl != null &amp;&amp; repliesColl.Count > 0)\n                {\n                    for (int iReplyCount = 0; iReplyCount &lt; repliesColl.Count; iReplyCount++)\n                    {\n                        discussionReply = repliesColl[iReplyCount];\n\n                        Console.WriteLine(\"Reply Content : \" + discussionReply[\"Body\"] +\"\\n\");\n\n                        FieldUserValue objUser = null;\n                        objUser = (FieldUserValue)discussionReply[\"Author\"];\n\n                        Console.WriteLine(\"Reply Author : \" + objUser.LookupValue+ \"\\n\");\n                    }\n                }\n            }\n        }\n\n        Console.ReadKey();\n    }\n\n    private static ListItemCollection GetAllRepliesFromSpecificTopic(string id, List lst, ClientContext ctx)\n    {\n        CamlQuery camlQuery = null;\n        ListItemCollection replies = null;\n\n        try\n        {\n            camlQuery = new CamlQuery();\n            camlQuery.ViewXml = \"&lt;View Scope=\\\"Recursive\\\"> \" +\n                                               \"&lt;Query>\" +\n                                               \"&lt;Where>\" +\n                                                           \"&lt;Eq>\" +\n                                                               \"&lt;FieldRef Name=\\\"ParentFolderId\\\" \/>\" +\n                                                               \"&lt;Value Type=\\\"Integer\\\">\" + id + \"&lt;\/Value>\" +\n                                                            \"&lt;Eq>\" +\n                                               \"&lt;\/Where>\" +\n                                               \"&lt;\/Query>\" +\n                                        \"&lt;\/View>\";\n\n            replies = lst.GetItems(camlQuery);\n            ctx.Load(replies);\n            ctx.ExecuteQuery();\n        }\n            catch (Exception ex) { }\n\n            return replies;\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>Result-\nDisplays &#8220;topic&#8221; and the content from replies and names of its\nauthors in console window.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/03\/2-1-1024x550.png\" alt=\"\" class=\"wp-image-6052\" width=\"549\" height=\"294\"\/><\/figure><\/div>\n\n\n\n<p><em><strong>Keywords: <\/strong><\/em><\/p>\n\n\n\n<p>How to retrieve SharePoint Discussion Board replies and other information programmatically in CSOM<br>Retrieve topic and Replies of Discussion board using CSOM<br>Read Discussion Board &amp; Replies using CSOM<br>Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM<br>How to access Discussion Lists Topics and Its Replies with Its Author value using CSOM<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we are going to retrieve all topics including replies and their authors values of a discussion list . Below image shows a discussion list having&nbsp; topic and its replies from different authors . In our blog we will see how to retrieve it using CSOM programmatically. Result- Displays &#8220;topic&#8221; and the content from replies and names of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-6050","post","type-post","status-publish","format-standard","hentry","category-sharepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"In this blog, we are going to retrieve all topics including replies and their authors values of a discussion list . Below image shows a discussion list having&nbsp; topic and its replies from different authors . In our blog we will see how to retrieve it using CSOM programmatically. Result- Displays &#8220;topic&#8221; and the content from replies and names of [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-17T10:11:34+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/","og_locale":"en_US","og_type":"article","og_title":"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM - Softree Technology","og_description":"In this blog, we are going to retrieve all topics including replies and their authors values of a discussion list . Below image shows a discussion list having&nbsp; topic and its replies from different authors . In our blog we will see how to retrieve it using CSOM programmatically. Result- Displays &#8220;topic&#8221; and the content from replies and names of [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/","og_site_name":"Softree Technology","article_published_time":"2020-03-17T10:11:34+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM","datePublished":"2020-03-17T10:11:34+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/"},"wordCount":131,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/03\/1-1-1024x603.png","articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/","name":"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#primaryimage"},"thumbnailUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/03\/1-1-1024x603.png","datePublished":"2020-03-17T10:11:34+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#primaryimage","url":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/03\/1-1-1024x603.png","contentUrl":"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2020\/03\/1-1-1024x603.png"},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-discussion-lists-topics-and-its-replies-with-its-author-value-using-csom\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Retrieve Discussion Lists Topics and Its Replies with Its Author value using CSOM"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6050"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6050\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}