Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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();
share|improve this question

2 Answers 2

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();
share|improve this answer
    
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 –  Kannan 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.

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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