簡體   English   中英

使用客戶端OM將新項目添加到SharePoint 2010列表中,而無需檢索整個列表

[英]Adding a new item to SharePoint 2010 list using client OM without retrieving the whole list

MSDN包含以下示例,用於將新項目添加到共享點列表:

 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

您總是可以使用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    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM