C # retrieve List data from Sharepoint
C # obtain List data from Sharepoint:
Add reference:
using Microsoft.SharePoint.Client;using System.Data;
Source code:
Public static void getDataFromSPList (string siteURL, string listName) {ClientContext clientContext = new ClientContext (siteURL); Web web = clientContext. web; ListCollection collList = web. lists; clientContext. load (collList); clientContext. executeQuery (); // remote interaction of Sharepoint is executed only after ExecuteQuery. Foreach (Microsoft. sharePoint. client. list list in collList) {Console. writeLine ("Title: {0}", list. title);} // CamlQuery camlQuery = new CamlQuery (); camlQuery. viewXml ="
"; Microsoft. sharePoint. client. list planlist = collList. getByTitle (listName); ListItemCollection collListItem = planlist. getItems (camlQuery); clientContext. load (collListItem, items => items. include (item => item. id, item => item. displayName, item => item. hasUniqueRoleAssignments); clientContext. executeQuery (); foreach (ListItem olistItem in collListItem) {Console. writeLine ("ID: {0} \ nDisplay name: {1} \ nUnique role assignments: {2}", olistItem. id, olistItem. displayName, olistItem. hasUniqueRoleAssignments);} clientContext. load (planlist); clientContext. executeQuery (); Console. writeLine (planlist. title. toString (); Console. writeLine (planlist. itemCount. toString (); Console. readKey ();}