MSDN有一个将新项目添加到sharepoint列表的示例:
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class CreateListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "My New Item!";
oListItem["Body"] = "Hello World!";
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class CreateListItem
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Title"] = "My New Item!";
oListItem["Body"] = "Hello World!";
oListItem.Update();
clientContext.ExecuteQuery();
}
}
}
我的问题是,此代码是否首先检索列表中存在的所有项目,然后添加新项目?
或者,它是否检索一个空列表,所以我可以以有效的方式添加项目?
谢谢,
ashilon
答案 0 :(得分:0)
您可以随时使用Fiddler
等网络工具检查请求在提供的示例中,既未检索列表项也未检索列表对象,请参阅以下注释:
var list = ctx.Web.Lists.GetByTitle(listTitle); //get List object reference (note, it is not initialized until requested from the server)
var itemCreateInfo = new ListItemCreationInformation();
var listItem = list.AddItem(itemCreateInfo);
listItem[propertyName] = propertyValue;
listItem.Update(); //prepare to create new List Item
ctx.ExecuteQuery(); //submit request to the server goes here