Attempt:
// see http://www.aspsnippets.com/Articles/Create-and-download-Excel-file-in-ASPNet.aspx
[HttpPost]
protected void FullDump ( object sender , EventArgs e )
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SurveyDbStaging"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Answers"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt, "Answers");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=SqlExport.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
}
}
}
}
called in the view by
$('#data-dump-button').click(function(){
$.ajax({
url : 'Excel/FullDump',
method : 'POST',
success: function () {
console.log("The success function was called!");
}
});
});
This just gives me
http://thesite.com/Excel/FullDump 404 (NOT FOUND)
in the console. What should I be doing instead?