问题
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