I come across to one class which is actually useful for creating a discussion because it has built in feature to do it.
I thought of sharing as of course with you all.
Here is a way to create discussion list programmatically.
First take an object of Web.
Considering that i am working in webpart.
SPWeb objWeb = SPContext.Current.Web;
objWeb.AllowUnsafeUpdates = true;
objWeb.Lists.Add("My DiscussionMalay", "MyDiscussion11", SPListTemplateType.DiscussionBoard);
Here all we need to do is use SPListTemplateType for creating Discussion.
Then main portion comes here,
SPListItem objItem = SPUtility.CreateNewDiscussion(objList.Items, "This is the subject of Discussion");
Check, SPUtility class actually allows us to create a discussion.
objItem[SPBuiltInFieldId.Body] = "This is the Body of the Discussion";
objItem.Update();
objWeb.Update();
objWeb.AllowUnsafeUpdates = false;
And That's it. your job is done...
No comments:
Post a Comment