I am using:
Response.Clear();
Response.ContentType = "pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
Response.WriteFile(this.txtFileName, true);
Response.Flush();
Response.End();
which shows a prompt to download the file and the prompt by default has "Open", "Save" and "Cancel" buttons with "Cancel" selec开发者_如何学Cted by default.
Is it possible for me to hide the "Open" button and force users to eitehr save or cancel?
This is a standard dialog provided by the browser. As far as I know there is no way to mess with it and there is also no reason to do that.
You should probably try to educate your users on how to use the browser (the problem with opening a large file is quite common, usually this ends up in some temp folder anyway), instead of trying to change its behavior.
No, it is impossible to hide the Open button. This behavior is (and should be) controlled by the user-agent.
You might want to try using this line instead:
Response.ContentType = "application/octet-stream";
When you set it to PDF, the browser tries to see if there is an application on the system to view PDFs (which there often is). If so, you get an open button.
I think, if you set it to the generic binary/octet-stream, the browser will only allow them to save.
Response.AppendHeader("X-Download-Options", "noopen")
in addition to any other settings to AppendHeader
精彩评论