创建具有甘特图视图的Sharepoint列表-以编程方式 [英] Create Sharepoint List which has gantt view - programmatically

查看:102
本文介绍了创建具有甘特图视图的Sharepoint列表-以编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Sharepoint的新手,所以了解的不多-我们将不胜感激任何帮助.

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

基本上我想以编程方式(在同一项目中):- 1.创建一个列表并使其成为甘特图 2.在列表中添加添加适当的列(将生成甘特图) 3.最后,我也想将值/数据添加到通过此代码创建的列中...

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

请提供任何帮助

非常感谢

推荐答案

尝试一下:

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

这篇关于创建具有甘特图视图的Sharepoint列表-以编程方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆