Hi all,

My code generates an excel file and should be sending it to the user for download. Instead, the user is getting the .aspx page as an .xls file! o.O

Can someone shed some light on this? Many thanks in advance

Code:
Response.ContentType = "application/x-msexcel";

System.IO.FileInfo fileToDownload = new System.IO.FileInfo(filename.ToString());
System.String disHeader = "Attachment; Filename=\"" + fileToDownload.Name + "\"";
Response.AppendHeader("Content-Disposition", disHeader);

Response.Flush();
Response.WriteFile(fileToDownload.FullName);