Thursday, 26 August 2010

Create ListItem using Client Object Model

Client Object model is very powerful feature of Sharepoint 2010.
You can use Client object model from remote computer to access sharepoint site and do CRUD operation.

Below is the sample code to create listitem using Sharepoint client object model.

// Create ClientContext Object
using (ClientContext clientContext = new ClientContext("http://sitename"))
// Give the credential
clientContext.Credentials = new System.Net.NetworkCredential("username", "password", "domainname");
Web site = clientContext.Web;
List list = clientContext.Web.Lists.GetByTitle("ListName");
// To use site object load it first
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem listItem = list.AddItem(itemCreateInfo);
listItem["Title"] = "Created through Client Object Model";
// Execute the query to push data on the server.

No comments:

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...