My data is being downloaded in an excel format. The following code executes flawlessly, however, the format is corrupted.
The file format and extension don't match is the error I receive. The file can be dangerous or corrupt. Don't open it unless you are confident in its source. Do you still intend to open it? When you say Yes, the file opens.
Please examine the code and explain what changes I need to do in order to obtain my data (Xls 97-2003 excel workbook).
if (dt4.Rows.Count > 0)
string filename = "DownloadMobileNoExcel.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt4;
//Get the HTML for the control.
//Write the HTML back to the browser.
//Response.ContentType = application/vnd.ms-excel;
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
this.EnableViewState = false;