retrieve sharepoint list data c#

Retrieve sharepoint list data using c#(server object model):


   First insert the following name space 

                 using Microsoft.SharePoint;

   Use the following code to retrive  list data

 protected void Page_Load(object sender, EventArgs e)
        {
          SPSite site = SPContext.Current.Site;
          SPWeb web = SPContext.Current.Web;
          SPList listobj = web.Lists["ListName"];
          SPQuery qry = new SPQuery();
          qry.Query = "<view/>";
          SPListItemCollection _icoll = listobj.GetItems(qry);

          foreach (SPListItem item in _icoll)
          {
              Label1.Text += Convert.ToString(item["ColumnName"]);
          }
        }
If you want to bind it to a GridView then see this GridView simple example , Clickable/Databound in GridView

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