posts - 27, comments - 21, trackbacks - 0

My Links

News

These postings are provided "AS IS" with no warranties, and confers no rights.
Locations of visitors to this page

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

 

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

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: