Friday, September 26, 2008

Creating Discussion list programmatically

Hi All,

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";



objWeb.AllowUnsafeUpdates = false;

And That's it. your job is done...

No comments:

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to