var CAML = "<Query>" + "<ViewAttributes Scope=\"Recursive\" />" + "<Where>" + "<Or>" + "<Eq>" + "<FieldRef Name=\"ID\"/>" + "<Value Type=\"Counter\">" + id + "</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name=\"ParentFolderId\" />" + "<Value Type=\"Integer\">" + id + "</Value>" + "</Eq>" + "</Or>" + "</Where>" + "</Query>"; var fieldinfo = "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Body' /><FieldRef Name='CorrectBodyToShow' /><FieldRef Name='Created' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='PersonalImage' /><FieldRef Name='DiscussionLastUpdated' /></ViewFields>"
And I only receive the top level item back...the Discussion Type item. There are 2 Message Type items related to the ParentFolderId of 1 but they do not get returned.
As an aside, if I run the CAML in the U2U tool it DOES return the entire thread...one Discussion and two Messages.
You need to set a property called Scope=Recursive. You've done this in your CAML but in the wrong place.
If you are using the object model then you would use
However you're using the web service. In your example you've put ViewAttributes as a child of the Query node - but this is incorrect.
It should be part of the queryOptions paramater of GetListItems
So in addition to your code above you would nee
var queryOptions = "<QueryOptions>" + "<ViewAttributes Scope='Recursive' />" + "</QueryOptions>";
listService.GetListItems("List_Name", null, CAML, fieldinfo , null, queryOptions, null);
the recursive feature is part of the query options object not the view options object in the web service
I have a hunch that you need to set the recusion in the SPQuery object, rather than in the query caml, eg:
qry.ExpandRecurrence = true
but I might be wrong :) I found that some sorting did not always work either.