How to force Chrome to open an "open file dialog" when downloading a file vía ASP.NET codebehind? How to force Chrome to open an "open file dialog" when downloading a file vía ASP.NET codebehind? google-chrome google-chrome

How to force Chrome to open an "open file dialog" when downloading a file vía ASP.NET codebehind?


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


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


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 dialogcontext.ApplicationInstance.CompleteRequest(); // send headers and c# server-side code still continueSystem.IO.File.Delete(filePath); // clean cache here if you needresponse.End();