Posted on: 11/21/2012 12:47:22 AM | Views : 571

I've been using some code that loads the contents of a dataset into Excel and then saves it to my local hard drive. This works perfectly in my development environment. I'm now trying to amend the code so that the file can be displayed or downloaded from the browser. I can get the file to download but when I open it I get an error :
Excel found unreadable content in 'Export.xlsx'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes. If I click yes Excel repairs the file and it opens with my data as expected.
Here is the code:
public static void ExportDSToExcelOpen(DataSet ds) { HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; HttpContext.Current.Response.AddHeader("content ...

Go to the complete details ...