0

I have to get all the field (column) values in an array from a SharePoint list. Right now I am looping through all the items in the list and creating an array. But it is very inefficient if I have large number of items.

What would be the most efficient way to get all the field (column) values in an array from SharePoint List?

Update 1: The array values are further used in the code and are not displayed to end user.

7
  • Why u r not using DatTable? Commented Dec 15, 2015 at 10:33
  • you looking for Jquery or CSOM/ SSOM ? Commented Dec 15, 2015 at 10:34
  • @Gaurravs: SSOM. But if its possible in CSOM then it should be available in SSOM, right? Commented Dec 15, 2015 at 10:37
  • @DikeshGandhi: SPList.GetDataTable() fetches me the data table. But then I cannot find any method in the DataTable Class that will return the column values in array. Or am I missing something here? Please elaborate what are you referring to. Commented Dec 15, 2015 at 10:40
  • 1
    I guess use of generic list can also suffice your requirement Commented Dec 15, 2015 at 11:24

1 Answer 1

0

Even I will suggest using DataTable than array

SPWeb oWebsite = SPContext.Current.Web;
SPList oList = oWebsite.Lists["List_Name"];
SPListItemCollection collListItems = oList.Items;

//DataTable oDataTable = collListItems.GetDataTable();

DataGrid1.DataSource = collListItems.GetDataTable();
DataGrid1.DataBind();

you can either use grid or the commented line if want in datatable format for further functionality.

Or

You can get list items collection in a generic list.

List<SPListItem> listItems = list.GetItems(query).Cast<SPListItem>().ToList();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.