An empty DataTable with column names from SharePoint 2010 List
-
12-12-2019 - |
Question
I am developing a project in SharePoint 2010.
My requirement is to get an empty DataTable but with column names in it from SharePoint List.
The .GetDataTable() method returns only if it has a value.
So basically I need a structure of the list in a DataTable.
Solution
This should give you an empty datatable if the GetDataTable does not retrieve column information.
DataTable _dt = new DataTable();
foreach (SPField spf in _lst.Fields)
{
_dt.Columns.Add(spf.InternalName.ToString(), spf.Type.GetType());
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow