1

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");
Response.BinaryWrite(file);
Response.End();
1
  • How did you solve this problem? Dec 17, 2019 at 10:53

2 Answers 2

1

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.Clear();
Response.AppendHeader("Content-Disposition:", "attachment; filename=" + filename);
Response.ContentType = "application/download";

...

SPFile file = web.GetFile(fullUrl);
Response.BinaryWrite(file.OpenBinary());

...

Response.Flush();
Response.End();
2
  • 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, 2012 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, 2012 at 8:43
1

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

http://mytechsoup.com/?p=36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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