Friday, May 4, 2012

how to add a list item into a list to sharepoint site in sharepoint 2010

Here i  will show  how to add a item to a list dynamically to share point root site.Then We have to get  the share point root site then add the items to list.The existing lists  will get by using GetList()  method .Finally we have to submit the changes of data context.

using (var dataContext = new MySharePointSite1L2spDataContext("http://localhost/test"))
{
  var Existingitems = dataContext.GetList<Item>("ItemMain");  
  Item Nitem = new Item();
  Nitem.Title = "Item for test";
  Nitem.Path = "/Lists/ItemMain";  
  
  Existingitems.InsertOnSubmit(Nitem);
  dataContext.SubmitChanges();
}


No comments:

Bel