0

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?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
sd_dracula
  • 3,796
  • 28
  • 87
  • 158

1 Answers1

1

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.

Squirrel5853
  • 2,376
  • 1
  • 18
  • 34
  • Ok, in that case that's fine and will do the job. Thanks for clearing that up. – sd_dracula Oct 21 '13 at 08:49
  • @sd_dracula I have just read [this question](http://stackoverflow.com/questions/11973293/force-user-to-download-rather-then-open-xlsx-file-in-browser) which talks about hiding the "type" of file downloading therefore hiding the open option. If that is what you want to achieve. – Squirrel5853 Oct 21 '13 at 08:52
  • Thanks Squirrel, will try that also. – sd_dracula Oct 21 '13 at 08:59