Wednesday, May 2, 2012

Add summary task to task list programatically



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:




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 sharepointkings@gmail.com 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 sharepointkings@gmail.com