In our project we are trying to implement PDF generation/download using the third party tool called “ephtmltopdf”. We have included the PDF generation code in our SharePoint 2010 visual web part and all works well till the user Clicks on download button for the first time. After the first download completes all the page post-back events are stopped.
Below is the code we are using to download the PDF.
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.Clear();
response.AddHeader("Content-Type", "binary/octet-stream");
response.AddHeader("Content-Disposition", "attachment; filename=ConversionResult.pdf; size=" + pdfBytes.Length.ToString());
response.Flush();
response.BinaryWrite(pdfBytes);
response.Flush();
response.End();
We tried searching for resources over the net and found that the issue is because we are stopping the current response stream using “response.End();” and this causes problems. We followed one more approach of opening a popup and performing download within that popup. Well download worked fine this time but we are not able to close the popup automatically on file download completion(User can close the popup using close icon but we don’t want to make user to close the popup). We are using the “SP.UI.ModalDialog.showModalDialog(options);” SharePoint modal dialog to open the dialog.
The major problem we are facing here is that none of the post-back events are triggering and we are not able to execute any client side script using “RegisterStartupScript” after the download complete action.
Let us know if anyone has faced this problem before.
0 comments:
கருத்துரையிடுக