Skip to content Skip to sidebar Skip to footer

Asp.net Downloading File Through Client Javascript Added In Eventhandler

I am not very skilled in ASP.NET and I have tried to: Update UI elements on an aspx site at the same time download a file I have this JS function: function downloadURL(url) {

Solution 1:

All they have to do with the MyDownloadHandler.ashx headers. If you add there this headers on your handler ashx

 HttpContext.Current.Response.ContentType = "application/octet-stream";
 HttpContext.Current.Response.AddHeader("Content-Disposition", 
                    "attachment; filename=" + SaveAsThisFileName);

then the browser will open the file save browser and not a new tab.

And you only have to do with javascript is

window.location = "MyDownloadHandler.ashx";

or just a simple link.

So to summarize, you have create a lot of code that is not necessary, and you make and a post back, that is also not necessary.

Relative: What is the best way to download file from serverError handling when downloading file from ASP.NET Web Handler (.ashx)

Post a Comment for "Asp.net Downloading File Through Client Javascript Added In Eventhandler"