Downloaded Excel sheet is corrupt

System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.Buffer = true;
response.Charset = “charset=utf-8”;
response.ContentType = “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”;
response.AddHeader(“content-disposition”, “attachment;filename=ExcelData.xlsx”);
response.BinaryWrite(File.ReadAllBytes(templateDir + “myFile.xlsx”));
response.Flush();
response.End();

The Excel File that is downloaded after the http request made to the Controller method is corrupted. The data/text is Excel file is not readable and modified. I am using the above mentioned code. Please help me to resolve this issue.

@sajidahmad,
Please try to set the content type as “application/xlsx” and see the document for reference.

If the problem still occur then share your sample application for our analysis.

Thanks :slightly_smiling_face: issue is resolved now

@sajidahmad,

Good to know that your issue is resolved now. In the event of further queries or issue, feel free write us back.