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):
- Create a List and make it a Gantt View
- Add add appropriate columns (that would generate the Gantt chart) to the list
- 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
精彩评论