I am working on c# and using the library to create an excel file, but it seems not to work properly. The task is very simple. I use a button which excutes an ajax call to connect to this function in the backend. However, even though it returns "success" I dont see any file locally downloaded.
Is there something I'm missing out?
AJAX Call
$.ajax({
url: 'WebService.asmx/downloadExcel',
type: 'POST',
data: { _result: $json },
success: function (response) {
console.log("success to download");
},
error: function (error) {
console.log("failed to download");
console.log(error);
}
});
WebService.cs - downloadExcel()
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.BufferOutput = true;
HttpContext.Current.Response.BinaryWrite(package.GetAsByteArray());
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=@C:/ExportData.xlsx");
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();