You can try with the ClosedXML library (to easily manipulate your workbook) saving it to a memory stream. Then, long story short, send the stream via http as usual.
public byte[] GetExcelByteStream(string filename)
{
using (var workbook = new XLWorkbook(filename))
{
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
using (var ms = new MemoryStream())
{
workbook.SaveAs(ms);
return ms.ToArray();
}
}
}
For the web response the classic way:
var excelStream = GetExcelByteStream("MyExcelFilename");
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "attachment;filename="+context.Request.Form["txtFileName"].ToString());
context.Response.AddHeader("Content-Length", excelStream.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.BinaryWrite(excelStream);
Hope it helps.