posts - 41, comments - 200, trackbacks - 0

My Links

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

Tag Cloud

Archives

Post Categories

Get all replies to a discussion

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();

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Saturday, October 10, 2009 3:40 AM | Filed Under [ MOSS WSS Development ]

Feedback

Gravatar

# re: Get all replies to a discussion

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.
3/18/2010 3:36 AM | Vishwanath
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: