When I want to export a report to Excel, the popup which asks ‘Open’, ‘Save’, ‘Cancel’ shows twice before opening Excel.
The following function is used.
public void StreamToBrowser(string fileName)
{
fileName += ExcelCreator.excelExt;
fileName=fileName.Replace("?",“aa”);
fileName=fileName.Replace("?",“AA”);
fileName=fileName.Replace("?",“ae”);
fileName=fileName.Replace("?",“AE”);
fileName=fileName.Replace("?",“oe”);
fileName=fileName.Replace("?",“OE”);
byte[] bFileName =null;
bFileName = Encoding.Default.GetBytes(fileName);
fileName = Encoding.ASCII.GetString(bFileName);
HttpContext.Current.Response.ContentType = “application/vnd.ms-excel”;
HttpContext.Current.Response.AddHeader(“content-disposition”, “attachment;filename=” + fileName + “”);
currentSheet.PageSetup.Orientation=PageOrientationType.Landscape;
excelApplication.Save(fileName, SaveType.OpenInBrowser, FileFormatType.Excel97, HttpContext.Current.Response);
}