Client Object Model and Linq to Sharepoint implementation

SharePoint 2010 Client side and server side code for CRUD list item. Sample contains client side object model

Sharepoint object model samples 
  Client Object Model  LINQ to SharePoint
Create List Items  string siteUrl = "http://cmsstores"; ClientContext clientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Students"); ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem oListItem = oList.AddItem(itemCreateInfo); oListItem["Firstname"] = txtFname.Text.Trim(); oListItem["Lastname"] = txtLname.Text.Trim(); oListItem.Update(); clientContext.ExecuteQuery();   try { using (MyEntitiesDataContext dc = new MyEntitiesDataContext(SPContext.Current.Site.Url)) { EntityList listItems = dc.GetList("Students"); StudentsItem objnew = new StudentsItem() { Firstname = txtFname.Text.Trim(), Lastname = txtLname.Text.Trim(), Country = Country.USA, Title = txtTitle.Text.Trim() };// Insert the new list item to the list dc.Students.InsertOnSubmit(objnew); dc.SubmitChanges(); } } catch (Exception ex) { throw; }
Update List Items  string siteUrl = "http://cmsstores"; ClientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Students"); ListItem oListItem = oList.GetItemById(6); oListItem["Firstname"] = txtFname.Text.Trim(); oListItem["Lastname"] = txtLname.Text.Trim(); oListItem.Update(); clientContext.ExecuteQuery();   try { using (MyEntitiesDataContext dc = new MyEntitiesDataContext(SPContext.Current.Site.Url)) { EntityList listItems = dc.GetList("Students"); StudentsItem updateobj = (from c in listItems where c.Id == 4 select c).First(); updateobj.Lastname = "Item2"; updateobj.Firstname = "Item2"; txtLname.Text = updateobj.Id.ToString(); dc.Students.InsertOnSubmit(updateobj); dc.SubmitChanges(); } } catch (Exception ex) { }  
Delete List Item  string siteUrl = "http://cmsstores"; ClientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Students"); ListItem oListItem = oList.GetItemById(6); oListItem.DeleteObject(); clientContext.ExecuteQuery();  try { using (MyEntitiesDataContext dc = new MyEntitiesDataContext(SPContext.Current.Site.Url)) { EntityList listItems = dc.GetList("Students"); var updateobj = (from c in listItems where c.Firstname == objTitle select c).First(); dc.Students.DeleteOnSubmit(updateobj); //Submit the changes dc.SubmitChanges(); } } catch (Exception ex) { }  

Similar Topics:

We will send you more information on Client Object Model and Linq to Sharepoint implementation.
Enter your email address:
This entry was posted in .Net, Sharepoint and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *