Skip to content

Instantly share code, notes, and snippets.

@shammelburg
Created May 8, 2017 10:24
Show Gist options
  • Save shammelburg/b3d3c08ca9c11978de1fdc747eb11bf6 to your computer and use it in GitHub Desktop.
Save shammelburg/b3d3c08ca9c11978de1fdc747eb11bf6 to your computer and use it in GitHub Desktop.
Create an excel file
string fileName = string.Empty;
var grid = new System.Web.UI.WebControls.GridView();
grid.DataSource = _db.spArtworkContentReport_ContentOnly_DI_Buyer(true, false).ToList();
fileName = "DataReport";
grid.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "_" + DateTime.Now.ToString() + ".xls");
Response.ContentType = "application/excel";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment