Convert SharePoint SpListCollection In DataTable With Decoded

Posted: November 7, 2014 in SharePoint2010, SharePoint2013

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);

}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s