Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

asp.net click button and download a file

Posted on 2011-10-28
1
Medium Priority
?
370 Views
Last Modified: 2012-06-21
I have some code that will create an excel file on the server.  How do I make it so that a button click will make the client open a save dialogue box so the user can download the file?
0
Comment
Question by:jackjohnson44
1 Comment
 
LVL 11

Accepted Solution

by:
b_levitt earned 2000 total points
ID: 37045057
in a button click event:

Response.Clear();
Response.ClearHeaders();

Response.ContentType = "application/ms-excel";
//can also be "inline" instead of "attachment" to display immediately
Response.AddHeader("Content-Disposition", "attachment; filename=DefaultSaveName.xls");
//you could also copy bytes to Reponse.OutputStream
Response.WriteFile(@"C:\temp\yourtempfile.xls");
Response.End()

0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question