Im trying to get values from "Discussions List", When I tried to get the values of "Body" field from that list its giving only the values of the replies of discussion. I couldn't access the values of the discussions, and also its giving exceptions when I try to get the custom column values.

SPSite oSpSite = SPContext.Current.Site;
SPWeb oSPWeb = oSpSite.OpenWeb();
SPList oSpListPost = oSPWeb.Lists["Discussions List"];
SPListItemCollection oSpListItemClnPost = oSpListPost.Items;

foreach (SPListItem post in oSpListItemClnPost)
    String synopsis = post["Body"].ToString(); 

This code only giving me the values of the replies of discussions, but I wanted to get the values of the discussions.

1 Answer 1


You need to change the view for this, if you look closely with your current code - look at the first post iteration, it starts from ID=2 instead of 1, change the view to enumerate over subject and reply both.

So instead of

SPListItemCollection oSpListItemClnPost = oSpListPost.Items;

try this

SPListItemCollection oSpListItemClnPost = oSpListPost.GetItems(oSpListPost.Views["Flat"]);

or any other view suitable to you.

Kindly let me know for any issue.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.