9

I have a page that sends a binari file, pdf, word or excel to web browser. In firefox, and IE both opens a dialog asking what do you whant to do with this file, "open" or "save"

enter image description here

but Chrome directly save it to your computer.

Is it possible to make Chrome ask you what do you want to do with this file, placing some metadata into web response before sending the file to browser?

Valentin Despa
  • 40,712
  • 18
  • 80
  • 106
anmarti
  • 5,045
  • 10
  • 55
  • 96

3 Answers3

13

It isn't possible to force Chrome to prompt the save dialog. The user has to change that behavior on chrome's configuration (advanced settings).

enter image description here

daniloquio
  • 3,822
  • 2
  • 36
  • 56
0

You need to send some headers so the browser knows how to handle the thing you are streaming like:

Response.ContentType 
Content-Disposition, application,and 
filename=" + FileName

which will force a download. Also refer this link for more information :

http://www.devtoolshed.com/aspnet-download-file-web-browser

Thanks

Dev
  • 6,570
  • 10
  • 66
  • 112
0

maybe it will be helpful

System.String filePath = "c:\\tempFile.pdf"
System.IO.FileInfo fileInfo = new FileInfo(filePath);

System.Web.HttpContext context = System.Web.HttpContext.Current;
System.Web.HttpResponse response = context.Response;
response.Clear();
response.ClearHeaders();
response.ClearContent();
response.ContentType = "application/pdf";
response.AppendHeader("content-type", "application/pdf");
response.AppendHeader("content-length", fileInfo.Length.ToString());
response.AppendHeader("content-disposition", String.Format("attachment; filename={0}.pdf", outputFileName));
response.TransmitFile(filePath);
response.Flush(); // this make stream and without it open chrome save dialog
context.ApplicationInstance.CompleteRequest(); // send headers and c# server-side code still continue

System.IO.File.Delete(filePath); // clean cache here if you need

response.End();
Bruno
  • 6,623
  • 5
  • 41
  • 47