In this blog we will explore the Convert sharepoint List SPListCollection in the Datatable with the decoded Column name.

protected void Page_Load(object sender, EventArgs e)

{

using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))

{

using (SPWeb oWeb = oSite.OpenWeb())

{

SPListCollection oListCollection = oWeb.Lists;

SPList oList = oWeb.Lists["ProjectInfo"];

SPListItemCollection oItems = oList.GetItems();

DataTable dtFirst = ConvertSPListToDataTable(oItems);

GridView1.DataSource = dtFirst;

GridView1.DataBind();

}

}

}

private static DataTable ConvertSPListToDataTable(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);

}

}

}