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.

Friday, March 29, 2013

Delete a SharePoint ListItem using silverLight Client Object Model



Write this in button click event.
private string siteUrl = "http://Spserver:100/";

try
            {
                ClientContext clientContext = new ClientContext(siteUrl);
                List oList = clientContext.Web.Lists.GetByTitle("New Ideas");
                ListItem oListItem = oList.GetItemById(4);
                oListItem.DeleteObject();
                clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
            }
            catch (Exception Ex)
            {
                lblErrorMessage.Content = Ex.ToString();
            }

private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
        {
            UpdateUIMethod updateUI = DisplayInfo;
            this.Dispatcher.BeginInvoke(updateUI);
        }

        private void DisplayInfo()
        {
            //MyOutput.Text = "New item created in " + oList.Title;
            lblErrorMessage.Content = "Item Deleted";
        }

        private delegate void UpdateUIMethod();

        private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
        {
            MessageBox.Show("Request failed. " + args.Message + "\n" + args.StackTrace);
        }

No comments:

Post a Comment