Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Thursday, December 01, 2011

Insert into SharePoint List in Client Object Model in a WebPart

SPWeb currentWeb = SPContext.Current.Web;
ClientContext ctx = new ClientContext(currentWeb.Url);
List loginList = ctx.Web.Lists.GetByTitle("Login");
ListItemCreationInformation newRecord = new
ListItemCreationInformation();
Microsoft.SharePoint.Client.ListItem item =
loginList.AddItem(newRecord);
item["Title"] = txtUserName.Text;
item["Password"] = txtPassWord.Text;
item.Update();
ctx.ExecuteQuery();
txtUserName.Text = "";
txtPassWord.Text = "";
strError += "Insertion Successful";

1 comment:

  1. Check out this link too...
    http://mindstick.com/Articles/50c4e9b3-2190-4bbf-9e57-035f228f1516/?Insert,%20Update,%20Delete%20in%20SharePoint%202010%20list%20using%20Client%20Object%20Model

    Its also having a wonderful explanation on Insert, Update, Delete in SharePoint 2010 list using Client Object Model.

    Thanks

    ReplyDelete