Create List Item:
ClientContext context = new ClientContext("Site Url");
Web site = context.Web;
List announcementsList = context.Web.Lists.GetByTitle("List Name");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = "test";
newItem["Col1"] = "";
newItem["Col2"] = "";
newItem["Col3"] = "";
newItem.Update();
context.ExecuteQuery();
Update list Item:
List Offboarding = context.Web.Lists.GetByTitle("List Name");
CamlQuery queryoff = new CamlQuery();
queryoff.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Query></View>";
ListItemCollection OffboardingItems = Offboarding.GetItems(queryoff);
context.Load(Offboarding);
context.Load(OffboardingItems);
context.ExecuteQuery();
foreach (var itemoff in OffboardingItems)
{
itemoff["Title"] = "test";
itemoff.Update();
}
context.ExecuteQuery();
ClientContext context = new ClientContext("Site Url");
Web site = context.Web;
List announcementsList = context.Web.Lists.GetByTitle("List Name");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = announcementsList.AddItem(itemCreateInfo);
newItem["Title"] = "test";
newItem["Col1"] = "";
newItem["Col2"] = "";
newItem["Col3"] = "";
newItem.Update();
context.ExecuteQuery();
Update list Item:
List Offboarding = context.Web.Lists.GetByTitle("List Name");
CamlQuery queryoff = new CamlQuery();
queryoff.ViewXml = "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + id + "</Value></Eq></Where></Query></View>";
ListItemCollection OffboardingItems = Offboarding.GetItems(queryoff);
context.Load(Offboarding);
context.Load(OffboardingItems);
context.ExecuteQuery();
foreach (var itemoff in OffboardingItems)
{
itemoff["Title"] = "test";
itemoff.Update();
}
context.ExecuteQuery();
No comments:
Post a Comment