I have created an application page to download file. I'm using the following code to download the file. After downloading file if I press the download button again it doesn't respond or post back. I assume calling Response.End() ends the connection between server and client. Is there any work around to this issue.

Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=output.pdf");
  • How did you solve this problem?
    – Fox
    Dec 17 '19 at 10:53

I've done this by using the code below (some lines not included), which is in the Page_Load method of the Application page.

The App page is loaded from a content page via a click on an asp:HyperLink control, which has CSS applied to make it look like a button.

Response.AppendHeader("Content-Disposition:", "attachment; filename=" + filename);
Response.ContentType = "application/download";


SPFile file = web.GetFile(fullUrl);


  • Hi Howard, Thanks for your reply. Actually i'm loading the application page via a click of a ribbon item that I created and then on the application page I'm generating a file programmatically and then calling the code above. I don't know how to load the application via a content page.. could you point to some samples Jan 20 '12 at 1:29
  • 1
    Well the content page simply hosts a user control, which is defined in the page's layout. This control renders the link. You can do the same thing with a custom web part, or even a standard content editor web part. The following link may help: msdn.microsoft.com/en-us/library/ms543497.aspx
    – Howard
    Jan 20 '12 at 8:43

The following link was very helpful in understanding the response issue that I was facing. It was solved by setting a few flags.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.