I am using the below code for export the data to excel sheet.
private void ExportToExcel(string fileName)
{
fileName = "MyXML.xls";
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
rptLinks.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
Everything is working fine but when I try to open the excel file MyXML.xls by double clicking, a popup/dialog box open with the below message :
"The file you are trying to open , MyXML.xls is in different format than specified by the file extension. " etc..
Can we make some changes in code so that no popup/dialog should come?