The Download Excel File button retreives a list of U.S. States in JSON format from the MySafeInfo Data API. The JSON data is converted to a strongly typed List<State> using Json.NET (Newtonsoft.Json). The List<State> is converted to a DataTable using ToDataTable extension method. The DataTable is converted to a byte[] using ToExcel extension method that uses EPPlus. The byte[] is then simply written back to the browser using Response.BinaryWrite.
List<State>
DataTable
byte[]
Response.BinaryWrite
The Read Excel File button reads the states.xlsx Excel file in to a StreamReader. The StreamReader underlying stream is converted to a DataTable using ToDataTable extension method. The DataTable is converted to a List<State> using ToList extension method. The List<State> is then serialized and output to a Literal to confirm that the Excel file was in fact read successfully.
StreamReader
Literal