In the system, it often happens that the excel stream is generated and the generated Excel is streamed to the user.
Generally speaking,
you can use Response to send an HTTP header to the client and send the Excel stream out.
But
there will be a problem.
The main reason whythe file download dialog box appears twice when you click to open is
: (current guess, the exact reason has not been found yet).
When it is opened for the first time, the temporary file of the excel stream already exists in the system (it is the file without the file extension), but there is no original one (the real file exists). The user is asked whether to save the temporary file to the computer. in other positions. (Is it related to the lack of suffix name?)
The second time, select the location of the client file and whether to save it to another non-temporary folder location.
The current solution is
to create a new page specifically to provide exported data
Write code like this in Page_load in this page
private void Page_Load(object sender, System.EventArgs e)
{
//Put user code here to initialize the page
ReportRule reportRule=new ReportRule();
byte[] result= reportRule.RenderReport(HttpContext.Current.Server.UrlDecode(this.Request.QueryString["peportpath"]),Request.QueryString["id"]); //Generate excel stream
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AppendHeader("Content-disposition","attachment;filename=hahh.xls");
HttpContext.Current.Response.BinaryWrite (result);
HttpContext.Current.Response.End();
}