TransWikia.com

Efficient way to get all the field (column) values in an array from SharePoint List

SharePoint Asked on February 2, 2021

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.

One Answer

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();

Answered by Gaurravs on February 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP