Online Training On SharePoint
                      

Friday, 9 October 2009

Creating new topics in Discussion Board and replies using Object Model

We had a requirments to create new discussions and the responses using SharePoint object model. Here is the code which we used to create this.

SPList oList = oWeb.Lists["My Discussion"]; 

SPListItemCollection myListItems = oList.Items; 

SPListItem oFirstItem = SPUtility.CreateNewDiscussion(myListItems, "Talk about Task X"); 

oFirstItem["Body"] = "What say you about task X?"; 

oFirstItem.Update(); 

SPListItem oReply1 = SPUtility.CreateNewDiscussionReply(oFirstItem); 

oReply1["Body"] = "my reply @" + DateTime.Now.ToString(); 

oReply1.Update(); 
Post a Comment
Related Posts with Thumbnails