Create Sharepoint List which has gantt view - programmatically

自作多情 提交于 2019-12-04 19:13:38

Try this:

using (SPSite site = new SPSite("http://yoursite/"))
{
    using (SPWeb web = site.OpenWeb())
    {
        Guid id = web.Lists.Add("listname", "descr", // 1
                                 SPListTemplateType.GanttTasks);

        SPList list = web.Lists[id]; // 2
        list.Fields.Add("display name", SPFieldType.Text, false);
        list.Update();

        // You should use "InternalName" to update your field values
        foreach (SPField field in list.Fields)
        {
            Console.WriteLine("{0}\t{1}", field.InternalName, field.Title);
        }

        SPListItem item = list.Items.Add(); // 3
        item["display name"] = "my value";
        item["PercentComplete"] = 1; // 100%
        item["StartDate"] = DateTime.Now;
        item["DueDate"] = new DateTime(2009, 12, 31);
        item.Update();

        Guid itemId = item.UniqueId;
        SPListItem itemUpdate = web.Lists["listname"].Items[itemId];
        itemUpdate["PercentComplete"] = .45; // 45%
        itemUpdate.Update();
    }
}

HTH

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!