You can use TransmitFile or WriteFile if the file is in the folder of your website.
string fileName = string.Format("Report_{0}.xlsx", reportId); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName)); Response.TransmitFile(fileName); Response.End();
Flow
If your data is already in memory, you want this method to write the response in pieces.
Stream stm1 = GenerateReport(Id); Int16 bufferSize = 1024; byte[] buffer = new byte[bufferSize + 1]; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"Report_{0}.xlsx\";", reportId)); Response.BufferOutput = false; int count = stm1.Read(buffer, 0, bufferSize); while (count > 0) { Response.OutputStream.Write(buffer, 0, count); count = stm1.Read(buffer, 0, bufferSize); }
Win
source share