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.
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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP