C#sp2010将项添加到列表中

时间:2011-01-14 18:05:27

标签: c# list sharepoint-2010

ClientContext ctx = new ClientContext("http://sp2010Server/sites/mySite");  
Web web = ctx.Web;

ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();  
ListItem listItem = web.Lists.GetByTitle("Site Requests").AddItem(itemCreateInfo);  
listItem["Title"] = "title";  
listItem["Description"] = "description";  
listItem["Url"] = "someUrl";  
listItem.Update();

我有上面的代码来更新sp2010列表,但它从不在列表中添加项目。我手动创建了一个名为“站点请求”的列表,并希望将一个项目添加到此列表中。我这样做对吗?我没有收到任何错误,代码执行正常,但列表中没有新项目。

1 个答案:

答案 0 :(得分:2)

请参阅:

http://msdn.microsoft.com/en-us/library/ee539976.aspx

ClientContext clientContext = new ClientContext("http://sp2010Server/sites/mySite");
SP.List oList = clientContext.Web.Lists.GetByTitle("Site Requests");

ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "title";
oListItem["Description"] = "description";
oListItem["Url"] = "someUrl";

oListItem.Update();

clientContext.ExecuteQuery();