Geeks With Blogs

News These postings are provided "AS IS" with no warranties, and confers no rights.
Locations of visitors to this page virtusa corp sharepoint virtusa.com shehan peruma

Shehan Peruma

A discussion list in unlike a normal list in that it consists of two content types  - a Discussion content type that maps to the discussion topic and a Message that maps to all replies to the topic. If you examine the Discussion content type you’ll see that its inherited from the Folder content type.

The reply contains a field called ‘ParentFolderId’ and as the name suggests it holds the ID of the discussion topic. So naturally if you were to do a query on the list for all items with the same ParentFolderId you would expect the query to work. However, since the topic is of a folder content type and the replies are contained within the ‘folder’ you would need to set the  queries ViewAttributes property to "Scope='Recursive'" for it to return results.

Below is an example using the object model:

SPQuery query = new SPQuery();
query.ViewAttributes = "Scope='Recursive'";
StringBuilder queryString = new StringBuilder();
queryString.Append("         <Where>");
queryString.Append("              <And>");
queryString.Append("                        <Eq>");
queryString.Append("                             <FieldRef Name=\"ContentType\" />");
queryString.Append("                             <Value Type=\"Text\">Message</Value>");
queryString.Append("                        </Eq>");
queryString.Append("                        <Eq>");
queryString.Append("                             <FieldRef Name=\"ParentFolderId\" />");
queryString.Append("                             <Value Type=\"Number\">99</Value>"); //NOTE: change this to the value you need
queryString.Append("                        </Eq>");
queryString.Append("              </And>");
queryString.Append("         </Where>");
query.Query = queryString.ToString();
DataTable replyTable = discussionList.GetItems(query).GetDataTable();

 

Posted on Saturday, October 10, 2009 3:40 AM MOSS , WSS , Development | Back to top


Comments on this post: Get all replies to a discussion

# re: Get all replies to a discussion
Requesting Gravatar...
Can you please let us know how to get the same code in sharepoint designer. We want to get all the replies to come in the body field.
Left by Vishwanath on Mar 18, 2010 3:36 AM

Your comment:
 (will show your gravatar)


Copyright © shehan | Powered by: GeeksWithBlogs.net