I have made the following button in C#, and it is returning a corrupt .xlsx file when the button is selected in the interface. The original file itself has no issues whatsoever.
protected void download_Data(object sender, EventArgs e)
{
string strFullPath = Server.MapPath("~/Content/Demo User data file.xlsx");
string strContents = null;
System.IO.StreamReader objReader = default(System.IO.StreamReader);
objReader = new System.IO.StreamReader(strFullPath);
strContents = objReader.ReadToEnd();
objReader.Close();
string attachment = "attachment; filename=Demo User data file.xlsx";
Response.ClearContent();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", attachment);
Response.Write(strContents);
Response.End();
}
Try this code
This works