Create Sharepoint List which has gantt view - programmatically

喜你入骨 提交于 2019-12-22 00:35:34

问题


I am new to sharepoint therefore don't know much - any help would be highly appreciated.

Basically i want to programatically (in the same project) :- 1. create a List and make it a Gantt View 2. Add add appropriate cololumns (that would generate the Gantt chart) to the List 3. And finally i would like to add values/data to the coloums created via this code too...

If there is a sample code or any tutorial...please

any help would be much appreciated please

thank you so much


回答1:


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



来源:https://stackoverflow.com/questions/1572528/create-sharepoint-list-which-has-gantt-view-programmatically

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