I'm trying to Export data from sqlServer to MS Excel file using vb.net framework 3.5 , everthing is working correctly and a save or open dialog opens up, when you save the file its saved but when trying to access the file i get a "Excel cannot open the file 'generated.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file" message. I've got MS Office 2007 installed.
P.S I take a template Excel Document and merging data into it to produce another document.
My code is as follows
Response.Clear()
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=generated.xlsx")
ExportToExcel(dt)
Response.Flush()
Response.End()
and added the following to the web.config file