get list items in sharepoint 2010 c# using client object model:

get list items in sharepoint 2010 c# using client object model:


Insert the following Namespace:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;

Use the following code.

        ListItemCollection _icoll;

        public MainPage()
        {
           InitializeComponent();

           ClientContext  ccsite = new ClientContext(ApplicationContext.Current.Url);
           ccsite.Load(ccsite.Web);
           List   listobj = ccsite.Web.Lists.GetByTitle("ListName");
           ccsite.Load(listobj);
        
            CamlQuery qry = new CamlQuery();
            qry.ViewXml = "<View/>";

             _icoll = listobj.GetItems(qry);
            ccsite.Load(_icoll);         
            ccsite.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(success), null);
        }

        private void success(object sender,ClientRequestSucceededEventArgs arg)
        {
            Dispatcher.BeginInvoke(datacon);
        }

        private void datacon()
        {
            foreach (ListItem item in _icoll)
            {    comboBox1.Items.Add(Convert.ToString(item["ColumnName"]));    }
        }
     

Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

A type named 'SP.Data. could not be resolved by the model error

Add content type to SharePoint List/Library using REST API