Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
Thanks alot bro.. Now its working fine –  Justin Roy Oct 18 '12 at 5:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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