using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPListCollection oListCollection = oWeb.Lists;
SPList oList = oWeb.Lists["List1"];
SPListItemCollection oItems = oList.GetItems();
DataTable dtFirst = ConvertSPListToDataTable(oItems);
}}
private static DataTable SPListToDataTable(SPListItemCollection spItemCollection)
{
DataTable dt = new DataTable();
try
{
dt = spItemCollection.GetDataTable();
foreach (DataColumn c in dt.Columns)
c.ColumnName = System.Xml.XmlConvert.DecodeName(c.ColumnName);
return (dt);
}
catch
{
return (dt);
}
}