Thursday, March 10, 2011

Download file from server

Download xlsx file from server
(already created)






public void GenerateXLSXFile(string fileName, ExcelDocument theDocument)
{
string filePath = Server.MapPath("~/TempFiles/" + fileName + ".xlsx");
theDocument.esd_WriteXLSXFile(filePath);

Response.Clear();
Response.AddHeader("Content-Type", "application/vnd.ms-excel");
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
Response.WriteFile(filePath);

Response.Flush();
System.IO.File.Delete(filePath);
Response.End();
}