asp.net click button and download a file

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?
jackjohnson44Asked:
Who is Participating?
 
b_levittCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.