简体   繁体   中英

Downloading a file from asp.net page

I am using the following code download a file from an asp.net page:

Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("Content-Disposition", "attachment; filename=Doc.xlsx");
Response.TransmitFile(Server.MapPath("Instructions/Doc.xlsx"));
Response.End();

That works fine, but is there a way to force the user to only be able to save the file? The method above gives the Open option also which means the user can edit the file on the server, which I do not want.

The code above is executed on a button click, is it possible to have that on a link instead?

The open option does not mean that the user will be modifying the file on the server.

What this actually means, to the user is, just show me the file but I don't care about keeping it. Therefore it is downloaded and stored in a temp directory, which will get cleaned up.

So both options it will be downloaded and saved.

You can hookup any code to anything you like, instead of a asp:button just use a asp:Linkbutton , which will appear as a hyperlink.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM