When we add summary task we need to ensure that we add it as a folder because summary task is not the alone list item type. it is actually a folder which contains another sub tasks.
Hence we can add summary task like this. I am taking an example of button click.
protected void btnAddSummaryTask_Click(Object sender, EventArgs e)
{
SPList myList = SPContext.Current.Web.Lists["Tasks"];
SPContentType type = myList.ContentTypes["Summary Task"];
SPListItem newItem = myList.Items.Add("{site url}/Lists/Tasks", SPFileSystemObjectType.Folder, "Summary Task Title");
newItem["ContentTypeId"] = type.Id;
newItem["Body"] = "This is a sample description";
//Set another fields as needed.
newItem.Update();
}
No comments:
Post a Comment