Convert sharepoint SpListCollection in Datatable with decoded

Sagarp
Posted by Sagarp under SharePoint category on | Points: 40 | Views : 6929
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);
}
}

Comments or Responses

Login to post response