开发者

Create Sharepoint List which has gantt view - programmatically

开发者 https://www.devze.com 2022-12-08 20:03 出处:网络
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):

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 columns (that would generate the Gantt chart) to the list
  3. And finally I would like to add values/data to the columns created via this code

If ther开发者_运维问答e is a sample code or any tutorial...please

Any help would be much appreciated please

Thank you so much


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号