Skip to content

Instantly share code, notes, and snippets.

@wiliammbr
Last active March 18, 2017 23:17
Show Gist options
  • Save wiliammbr/8224402 to your computer and use it in GitHub Desktop.
Save wiliammbr/8224402 to your computer and use it in GitHub Desktop.
// creates a new SharePoint context
// passing the parameters
ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new NetworkCredential("wiliammbr", "password", "domain");
// selects the list by title
SP.List list = clientContext.Web.Lists.GetByTitle(listTitle);
// creates a new object to include the new list item
// this object helps you on defining which target folder the list item
// is going to be saved and other settings
SP.ListItemCreationInformation itemCreateInfo = new SP.ListItemCreationInformation();
// adds the new item to the list with ListItemCreationInformation
SP.ListItem listItem = list.AddItem(itemCreateInfo);
// fill the fields with the required information
listItem["Title"] = "New Item!";
listItem["OtherField"] = "Some important information.";
listItem.Update();
// executes the creation of the new list item on SharePoint
clientContext.ExecuteQuery();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment