Log in

View Full Version : Download Excel file link



padders01
11-27-2015, 11:29 AM
Hi,

I have code that works to create an Excel file of data presented on my .asp page.

The code automatically downloads the file when I access the page. How do it get it to work only when a link is clicked.

The code I am using is



<%
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "filename=excelfile.xls"
%>

Thanks

Beverleyh
11-27-2015, 12:21 PM
I'm not an ASP user but I would imagine you can write the file download code into a function and call it onclick.

Try http://stackoverflow.com/questions/14034960/asp-net-how-to-make-linkbutton-function-as-hyperlink

Or how about creating a link that points to a file (e.g. 'download.asp'), and then put only your file download code into that file.

padders01
11-27-2015, 01:24 PM
Great, that's given me an idea and I have it working now

Thank you